Disclaimer

This work is very preliminary as I get back into the coding swing of things. Data wrangling and figure generation will be done via R, but the rest of the project will be done using good ol’ microsoft products. This is just an entry point into data crunching and should by no means be considered a final product.

Also, I’m not great at this but whatever. I could automate this, but I’ll figure that out shortly!

Need to update figures & analyze sites for seasonal trends

Methodology

SNOTEL data was provided by the NRCS. Data was cleaned by removing outliers that are likely implausible; any year with more than 15 observations missing was removed. Temperatures were adjusted using the Morrisey method for stations identified by Ma et al (2019) due to SNOTEL temperature sensor changes, with the adjustment applied to pre-sensor change data. Daily mean observations were detrended to determine whether values were increasing or decreasing from the entire time series trend. Daily mean temperatures were first averaged by water year, with all water year means then averaged by day of water year. The mean temperature by day for the period of record was averaged. To find the standard deviation, the daily mean temperatures by water year was subtracted from the averaged mean temperature by day for the period of record. All water year means averaged by day of water year were subtracted from the temperature mean. The resulting values were then added together to find the “residual” of the daily mean temperatures by water year. The standard deviation was then computed from those residuals, with trends analyzed by Mann‐Kendall significance test and Theil‐Sen’s rate of change. Significant trends are identified with p-values of less than 0.10.

Morrisey Method

The Morrisey Method is taken from Ma, Fassnacht and Kampf..

In R script: T(adjusted) = 5.3x10(-7)xT(old)4+3.72x10(-5)xT(old)3-2.16x10(-3)xT(old)2-7.32x10^(-2)xT(old)+1.37

In the Ma et al. spreadsheet, H1 is Morrisey, H2 is Oiler

03/01/2023 update

Analyzing by summer and winter season for each station’s timeseries, using the shifted mean of the time series, then sigmoidal detrending. Standard deviation is taken with the relevant days of the water year.

03/06/2023 update

Analyzing by spring and fall season as well….

San Juan Area SNOTEL sites:

Beartown 327 Original 4/18/2005

Cascade #2 387 Morrisey 6/18/2004

Cumbres Trestle 431 Oyler -> Morrisey 6/8/2005

Idarado 538 Morrisey 7/12/2004

Lone Cone 589 Oyler -> Morrisey 6/22/2005

Middle Creek 624 Morrisey 6/26/2006

Mineral Creek 629 Oyler ?? -> Morrisey 6/22/2004

Molas Lake 632 NSCE-Morrisey, Bias-Original 10/2/2003

Red Mountain Pass 713 Morrisey 8/18/2004

Scotch Creek 739 Morrisey 6/15/2004

Slumgullion 762 Morrisey 6/26/2006

Spud Mountain 780 Morrisey 6/28/2004

Stump Lakes 797 Morrisey 7/22/2005

Upper Rio Grande 839 Oyler -> Morrisey 5/26/2004 *Why is this in red?

Upper San Juan 840 Morrisey 4/7/2004

Vallecito 843 Morrisey 7/22/2005

Wolf Creek Summit 874 Morrisey 7/12/2004

Data from thesis research:


SNOTEL_san_juan_Area <- snotel_download(site_id = c(327, 387, 431, 538, 589, 624, 629, 632, 713, 739, 762, 780, 797, 839, 840, 843, 874), path = tempdir('../data'), internal = TRUE)

write.csv(SNOTEL_san_juan_Area,"C:/Users/13074/Documents/ESS580/thesis_project/San_Juan_area/data_raw/snotel_san_juans.csv", row.names = FALSE) #write in the raw data

Beartown 327

Original

SNOTEL_san_juan_Area <- read.csv("C:/Users/13074/Documents/ESS580/thesis_project/San_Juan_area/data_raw/snotel_san_juans.csv", header = TRUE)

snotel_327 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "327")
#str(snotel_327) # check the date, usually a character.  

snotel_327$Date <- as.Date(snotel_327$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_327_clean <- snotel_327 %>% # filter for the timeframe
  filter(Date >= "1983-08-10" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_327_clean <- snotel_327_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_327_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_327_clean <- snotel_327_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_min > -40)
ggplot(snotel_327_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
snotel_327_cull_count <- snotel_327_clean %>% 
  filter(temperature_min < -40) %>% 
  count(waterYear)

snotel_327_cull_count
## # A tibble: 0 x 2
## # Groups:   waterYear [0]
## # ... with 2 variables: waterYear <dbl>, n <int>
# filtering for too few observations in a year
snotel_327_cull_count_days <- snotel_327_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_327_cull_count_days
## # A tibble: 3 x 2
## # Groups:   waterYear [3]
##   waterYear     n
##       <dbl> <int>
## 1      1983    52
## 2      1994   337
## 3      2003   346

1983, 1994, 2003 need to be culled.

snotel_327_clean_culled <- snotel_327_clean %>% 
  filter(waterYear != "1983" & waterYear != "1994" & waterYear != "2003") #%>% 
  #filter(temperature_mean > -49)

Beartown (327) NOT ADJUSTED.

2005-04-18 installed ext range sensor. Original

snotel_327_adjusted <- snotel_327_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2005-04-18", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

327 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_327 <- snotel_327_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_327 <- yearly_wy_aver_327 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(temperature_mean))

#average mean temperature by day for the period of record:

daily_wy_aver_327 <- daily_wy_aver_327 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_327$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_327 <-daily_wy_aver_327 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_327$date_temp <- signif(daily_wy_aver2_327$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_327, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

327 SD

standard_dev_327 <- daily_wy_aver_327 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_327 <- standard_dev_327 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_327 <- standard_dev_all_327 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_327 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 3.665035
1985 3.686429
1986 3.664307
1987 3.362492
1988 3.612639
1989 4.359147
1990 3.454469
1991 3.409149
1992 3.129564
1993 3.078949
1995 3.528161
1996 3.744390
1997 3.647314
1998 3.473108
1999 3.476285
2000 3.511314
2001 3.498060
2002 3.240920
2004 3.681379
2005 3.189362
2006 3.405627
2007 3.440844
2008 3.405455
2009 3.453381
2010 3.345493
2011 3.639763
2012 3.235449
2013 3.684196
2014 3.297641
2015 3.325890
2016 3.375989
2017 3.554136
2018 3.153533
2019 3.276741
2020 3.310045
2021 3.331628
2022 3.398441
ggplot(standard_dev_all_327, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 327 average temperatures for water years 2005-2021

MK & SS for 327 (non-corrected)

sd_mk_327 <- mk.test(standard_dev_all_327$sd_2)
print(sd_mk_327)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_327$sd_2
## z = -2.655, n = 37, p-value = 0.007931
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -204.0000000 5846.0000000   -0.3063063
sd_sens_327 <- sens.slope(standard_dev_all_327$sd_2)
print(sd_sens_327)
## 
##  Sen's slope
## 
## data:  standard_dev_all_327$sd_2
## z = -2.655, n = 37, p-value = 0.007931
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.012802754 -0.002166772
## sample estimates:
## Sen's slope 
## -0.00880668

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_327 <- standard_dev_327 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_327 <- summer_standard_dev_all_327 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_327 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 1.860569
1985 2.062082
1986 1.960777
1987 1.808828
1988 2.110240
1989 2.258987
1990 2.283263
1991 1.679224
1992 2.183776
1993 2.381223
1995 2.826314
1996 1.875152
1997 1.921171
1998 2.418465
1999 1.963117
2000 1.691296
2001 2.116042
2002 2.106926
2004 2.177981
2005 2.001868
2006 1.991639
2007 1.885505
2008 1.819079
2009 1.887569
2010 2.150694
2011 1.434396
2012 1.661522
2013 1.910140
2014 1.648904
2015 1.972911
2016 2.195565
2017 1.673705
2018 1.644285
2019 2.085934
2020 2.009090
2021 2.347642
2022 2.202137
ggplot(summer_standard_dev_all_327, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 327 average summer temperatures for water years 2005-2021

summer MK & SS for 327 (non-corrected)

summer_sd_mk_327 <- mk.test(summer_standard_dev_all_327$sd_2)
print(summer_sd_mk_327)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_327$sd_2
## z = -0.69318, n = 37, p-value = 0.4882
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -54.00000000 5846.00000000   -0.08108108
summer_sd_sens_327 <- sens.slope(summer_standard_dev_all_327$sd_2)
print(summer_sd_sens_327)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_327$sd_2
## z = -0.69318, n = 37, p-value = 0.4882
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.012810145  0.004602835
## sample estimates:
##  Sen's slope 
## -0.003201941

Winter

winter_standard_dev_all_327 <- standard_dev_327 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_327 <- winter_standard_dev_all_327 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_327 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 4.409946
1985 4.274595
1986 4.628766
1987 4.346398
1988 4.396210
1989 4.808450
1990 4.387705
1991 4.256565
1992 3.128869
1993 3.531408
1995 4.108458
1996 4.405725
1997 4.352440
1998 4.003164
1999 3.940296
2000 4.335288
2001 4.197367
2002 3.934723
2004 4.512035
2005 3.985123
2006 4.232908
2007 4.442272
2008 4.245334
2009 4.195893
2010 3.564631
2011 4.702820
2012 4.015484
2013 4.858486
2014 3.714399
2015 3.996462
2016 4.358429
2017 4.265141
2018 3.969924
2019 3.822473
2020 3.659924
2021 3.885000
2022 4.025535
ggplot(winter_standard_dev_all_327, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 327 average winter temperatures for water years 2005-2021

winter MK & SS for 327 (non-corrected)

winter_sd_mk_327 <- mk.test(winter_standard_dev_all_327$sd_2)
print(winter_sd_mk_327)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_327$sd_2
## z = -2.2103, n = 37, p-value = 0.02708
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -170.0000000 5846.0000000   -0.2552553
winter_sd_sens_327 <- sens.slope(winter_standard_dev_all_327$sd_2)
print(winter_sd_sens_327)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_327$sd_2
## z = -2.2103, n = 37, p-value = 0.02708
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.020752425 -0.001453077
## sample estimates:
## Sen's slope 
## -0.01160069

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_327 <- standard_dev_327 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_327 <- spring_standard_dev_all_327 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_327 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 4.540103
1985 2.999524
1986 3.480058
1987 3.115465
1988 3.702310
1989 3.917868
1990 2.473751
1991 3.608365
1992 2.968327
1993 3.022708
1995 3.175124
1996 3.949935
1997 3.633635
1998 3.280054
1999 3.645717
2000 3.660867
2001 3.442424
2002 2.823788
2004 3.044119
2005 3.170653
2006 2.742494
2007 3.086009
2008 3.306762
2009 3.229162
2010 3.750745
2011 3.768059
2012 3.119457
2013 3.172186
2014 3.876897
2015 2.820340
2016 2.850230
2017 3.851142
2018 2.970587
2019 3.568761
2020 2.969466
2021 2.950515
2022 3.500200
ggplot(spring_standard_dev_all_327, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 327 average spring temperatures for water years 2005-2021

spring MK & SS for 327 (non-corrected)

spring_sd_mk_327 <- mk.test(spring_standard_dev_all_327$sd_2)
print(spring_sd_mk_327)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_327$sd_2
## z = -0.85013, n = 37, p-value = 0.3953
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -66.0000000 5846.0000000   -0.0990991
spring_sd_sens_327 <- sens.slope(spring_standard_dev_all_327$sd_2)
print(spring_sd_sens_327)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_327$sd_2
## z = -0.85013, n = 37, p-value = 0.3953
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.022224566  0.009077325
## sample estimates:
##  Sen's slope 
## -0.005203484

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_327 <- standard_dev_327 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_327 <- fall_standard_dev_all_327 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_327 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 2.277081
1985 3.394671
1986 2.636639
1987 2.288469
1988 2.558383
1989 5.711995
1990 3.182492
1991 2.626358
1992 3.673505
1993 2.629343
1995 2.834913
1996 3.655773
1997 3.733356
1998 3.399398
1999 2.891398
2000 2.950439
2001 2.580336
2002 2.325556
2004 3.511525
2005 2.257804
2006 2.938945
2007 2.463740
2008 2.937552
2009 3.013537
2010 3.796847
2011 2.519665
2012 2.675583
2013 2.613231
2014 3.311425
2015 2.358478
2016 2.279209
2017 3.069788
2018 2.575260
2019 2.830616
2020 4.096601
2021 2.931688
2022 3.029303
ggplot(fall_standard_dev_all_327, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 327 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 327 (non-corrected)

fall_sd_mk_327 <- mk.test(fall_standard_dev_all_327$sd_2)
print(fall_sd_mk_327)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_327$sd_2
## z = 0.013079, n = 37, p-value = 0.9896
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 2.000000e+00 5.846000e+03 3.003003e-03
fall_sd_sens_327 <- sens.slope(fall_standard_dev_all_327$sd_2)
print(fall_sd_sens_327)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_327$sd_2
## z = 0.013079, n = 37, p-value = 0.9896
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01829212  0.01627292
## sample estimates:
## Sen's slope 
## 0.000232427

Cascade #2 387

Morrisey 6/18/2004

snotel_387 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "387")
#str(snotel_387) # check the date, usually a character.  

snotel_387$Date <- as.Date(snotel_387$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_387_clean <- snotel_387 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_387_clean <- snotel_387_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_387_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_387_clean <- snotel_387_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_min > -40) %>% 
  filter(temperature_mean > -40)
ggplot(snotel_387_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

temp_387_xts <- xts(snotel_387_clean$temperature_mean, order.by = snotel_387_clean$Date)

dygraph(temp_387_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
snotel_387_cull_count <- snotel_387_clean %>% 
  filter(temperature_min > -40) %>% 
  count(waterYear)

snotel_387_cull_count
## # A tibble: 32 x 2
## # Groups:   waterYear [32]
##    waterYear     n
##        <dbl> <int>
##  1      1991   358
##  2      1992   364
##  3      1993     1
##  4      1994   348
##  5      1995   363
##  6      1996   360
##  7      1997   362
##  8      1998   362
##  9      1999   362
## 10      2000   365
## # ... with 22 more rows
# filtering for too few observations in a year
snotel_387_cull_count_days <- snotel_387_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_387_cull_count_days
## # A tibble: 4 x 2
## # Groups:   waterYear [4]
##   waterYear     n
##       <dbl> <int>
## 1      1993     1
## 2      1994   348
## 3      2018   334
## 4      2022   335

1993, 1994, 2018, 2022 need to be culled.

snotel_387_clean_culled <- snotel_387_clean %>% 
  filter(waterYear != "1993" & waterYear != "1994" & waterYear != "2018" & waterYear != "2022") #%>% 
  #filter(temperature_mean > -49)

Cascade #2 (387) NOT ADJUSTED.

Morrisey 6/18/2004

snotel_387_adjusted <- snotel_387_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2004-06-18", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

387 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_387 <- snotel_387_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

#THIS IS WRONG.
#daily_wy_aver_387 <- yearly_wy_aver_387 %>% 
#  group_by(daymonth) %>% 
# mutate(aver_day_temp = mean(temperature_mean))

#TRYING:
daily_wy_aver_387 <- yearly_wy_aver_387 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(temperature_mean))


#average mean temperature by day for the period of record:

daily_wy_aver_387 <- daily_wy_aver_387 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_387$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_387 <-daily_wy_aver_387 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_387$date_temp <- signif(daily_wy_aver2_387$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_387, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

387 SD

standard_dev_387 <- daily_wy_aver_387 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

detrend_check <- standard_dev_387 %>% 
  filter(waterYear == 2000)

ggplot(detrend_check, aes(x = waterDay, y = residual))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

standard_dev_all_387 <- standard_dev_387 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_387 <- standard_dev_all_387 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_387 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1991 3.522112
1992 2.994859
1995 3.441946
1996 3.932167
1997 3.324398
1998 3.424743
1999 3.127246
2000 3.084709
2001 3.320611
2002 3.405058
2003 3.162981
2004 3.339242
2005 2.906195
2006 3.154401
2007 3.137724
2008 3.026366
2009 3.082639
2010 2.811441
2011 3.322650
2012 2.819630
2013 3.356654
2014 3.068807
2015 3.139275
2016 3.097158
2017 3.158072
2019 2.991383
2020 2.866334
2021 3.004896
ggplot(standard_dev_all_387, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 387 average temperatures for water years 2005-2021

MK & SS for 387 (non-corrected)

# Thus is giving an error, omitting it as it does not matter due to the correction. 
sd_mk_387 <- mk.test(standard_dev_all_387$sd_2)
print(sd_mk_387)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_387$sd_2
## z = -2.9832, n = 28, p-value = 0.002852
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -152.0000000 2562.0000000   -0.4021164
sd_sens_387 <- sens.slope(standard_dev_all_387$sd_2)
print(sd_sens_387)
## 
##  Sen's slope
## 
## data:  standard_dev_all_387$sd_2
## z = -2.9832, n = 28, p-value = 0.002852
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.026140505 -0.005184818
## sample estimates:
## Sen's slope 
## -0.01613817

Corrected

387 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_387_ad <- snotel_387_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
# WRONG.
# daily_wy_aver_387_ad <- yearly_wy_aver_387_ad %>% 
#   group_by(daymonth) %>% 
#   mutate(aver_day_temp_ad = mean(temp_ad))

#CORRECT:

daily_wy_aver_387_ad <- yearly_wy_aver_387_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(temp_ad))


#average mean temperature by day for the period of record:
daily_wy_aver_387_ad <- daily_wy_aver_387_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_387_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_387_ad <-daily_wy_aver_387_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_387_ad$date_temp_ad <- signif(daily_wy_aver2_387_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_387_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

387 SS (corrected)

standard_dev_387_ad <- daily_wy_aver_387_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_387_ad <- standard_dev_387_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_387_ad <- standard_dev_all_387_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_387_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1991 3.305535
1992 2.832407
1995 3.219636
1996 3.655387
1997 3.096437
1998 3.149301
1999 3.009141
2000 2.843226
2001 3.059668
2002 3.056919
2003 2.905551
2004 3.171641
2005 2.882486
2006 3.106493
2007 3.129519
2008 3.052507
2009 3.034764
2010 2.852227
2011 3.326550
2012 2.833130
2013 3.384809
2014 3.037671
2015 3.048926
2016 3.066199
2017 3.114679
2019 3.008721
2020 2.900680
2021 3.018762
ggplot(standard_dev_all_387_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 387 average temperatures for water years 1986-2021

MK & SS 387 (corrected)

sd_mk_387_ad <- mk.test(standard_dev_all_387_ad$sd_2)
print(sd_mk_387_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_387_ad$sd_2
## z = -1.1656, n = 28, p-value = 0.2438
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -60.0000000 2562.0000000   -0.1587302
sd_sens_387_ad <- sens.slope(standard_dev_all_387_ad$sd_2)
print(sd_sens_387_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_387_ad$sd_2
## z = -1.1656, n = 28, p-value = 0.2438
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.011637109  0.003308211
## sample estimates:
##  Sen's slope 
## -0.004011501

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_387 <- standard_dev_387 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_387 <- summer_standard_dev_all_387 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_387 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1991 2.292293
1992 2.265236
1995 2.905795
1996 2.646515
1997 2.342115
1998 2.861007
1999 2.063686
2000 1.868415
2001 2.232178
2002 2.232756
2003 2.328358
2004 2.166668
2005 2.037677
2006 2.105026
2007 1.966957
2008 1.885119
2009 2.229343
2010 2.169285
2011 1.512771
2012 1.590099
2013 2.211761
2014 1.658257
2015 2.059384
2016 2.176331
2017 1.896572
2019 2.125892
2020 1.947163
2021 2.435872
ggplot(summer_standard_dev_all_387, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 387 average summer temperatures for water years 2005-2021

summer MK & SS for 387 (non-corrected)

summer_sd_mk_387 <- mk.test(summer_standard_dev_all_387$sd_2)
print(summer_sd_mk_387)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_387$sd_2
## z = -2.6671, n = 28, p-value = 0.00765
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -136.0000000 2562.0000000   -0.3597884
summer_sd_sens_387 <- sens.slope(summer_standard_dev_all_387$sd_2)
print(summer_sd_sens_387)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_387$sd_2
## z = -2.6671, n = 28, p-value = 0.00765
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.033908806 -0.004395614
## sample estimates:
## Sen's slope 
## -0.01625865

Winter

winter_standard_dev_all_387 <- standard_dev_387 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_387 <- winter_standard_dev_all_387 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_387 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1991 4.077277
1992 3.003195
1995 3.947447
1996 4.262043
1997 3.684259
1998 3.646514
1999 3.458377
2000 3.597954
2001 3.822712
2002 3.812673
2003 3.437409
2004 3.962826
2005 3.463378
2006 3.796493
2007 3.895291
2008 3.752832
2009 3.558828
2010 2.833342
2011 4.193394
2012 3.361782
2013 4.264060
2014 3.528521
2015 3.333524
2016 3.777723
2017 3.594331
2019 3.296378
2020 3.081604
2021 3.412868
ggplot(winter_standard_dev_all_387, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 387 average winter temperatures for water years 2005-2021

winter MK & SS for 387 (non-corrected)

winter_sd_mk_387 <- mk.test(winter_standard_dev_all_387$sd_2)
print(winter_sd_mk_387)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_387$sd_2
## z = -1.9559, n = 28, p-value = 0.05048
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -100.0000000 2562.0000000   -0.2645503
winter_sd_sens_387 <- sens.slope(winter_standard_dev_all_387$sd_2)
print(winter_sd_sens_387)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_387$sd_2
## z = -1.9559, n = 28, p-value = 0.05048
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.0309608139  0.0001186329
## sample estimates:
## Sen's slope 
## -0.01519784

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_387_ad <- standard_dev_387_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_387_ad <- summer_standard_dev_all_387_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_387_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1991 2.046961
1992 2.027960
1995 2.602752
1996 2.380479
1997 2.094740
1998 2.551386
1999 1.846510
2000 1.686471
2001 2.009388
2002 2.008439
2003 2.069059
2004 2.119688
2005 2.071080
2006 2.078772
2007 1.964899
2008 1.883095
2009 2.256452
2010 2.157645
2011 1.512336
2012 1.564691
2013 2.185031
2014 1.651407
2015 2.050128
2016 2.163809
2017 1.872004
2019 2.129628
2020 1.951988
2021 2.403331
ggplot(summer_standard_dev_all_387_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 387 average summer temperatures for water years 1986-2021

summer MK & SS 387 (corrected)

summer_sd_mk_387_ad <- mk.test(summer_standard_dev_all_387_ad$sd_2)
print(summer_sd_mk_387_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_387_ad$sd_2
## z = -0.49391, n = 28, p-value = 0.6214
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -26.00000000 2562.00000000   -0.06878307
summer_sd_sens_387_ad <- sens.slope(summer_standard_dev_all_387_ad$sd_2)
print(summer_sd_sens_387_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_387_ad$sd_2
## z = -0.49391, n = 28, p-value = 0.6214
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.018827648  0.007260316
## sample estimates:
## Sen's slope 
## -0.00318582

Winter

winter_standard_dev_all_387_ad <- standard_dev_387_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_387_ad <- winter_standard_dev_all_387_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_387_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1991 3.936431
1992 2.856860
1995 3.758141
1996 4.049642
1997 3.491265
1998 3.479854
1999 3.293140
2000 3.394557
2001 3.667701
2002 3.605148
2003 3.275287
2004 3.756823
2005 3.442720
2006 3.781750
2007 3.902946
2008 3.771192
2009 3.554481
2010 2.841566
2011 4.187795
2012 3.358280
2013 4.268340
2014 3.517837
2015 3.338050
2016 3.770826
2017 3.609237
2019 3.282296
2020 3.078393
2021 3.402322
ggplot(winter_standard_dev_all_387_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 387 average winter temperatures for water years 1986-2021

winter MK & SS 387 (corrected)

winter_sd_mk_387_ad <- mk.test(winter_standard_dev_all_387_ad$sd_2)
print(winter_sd_mk_387_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_387_ad$sd_2
## z = -0.69148, n = 28, p-value = 0.4893
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -36.0000000 2562.0000000   -0.0952381
winter_sd_sens_387_ad <- sens.slope(winter_standard_dev_all_387_ad$sd_2)
print(winter_sd_sens_387_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_387_ad$sd_2
## z = -0.69148, n = 28, p-value = 0.4893
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02215632  0.01285433
## sample estimates:
##  Sen's slope 
## -0.006755843

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_387 <- standard_dev_387 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_387 <- spring_standard_dev_all_387 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_387 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1991 3.636730
1992 2.642100
1995 2.970590
1996 4.727108
1997 3.700243
1998 3.654964
1999 3.329554
2000 3.336091
2001 3.426403
2002 2.699057
2003 3.436787
2004 2.854011
2005 3.020931
2006 2.419970
2007 2.971614
2008 2.860361
2009 2.867990
2010 3.273746
2011 3.522515
2012 2.907653
2013 2.877217
2014 3.390005
2015 3.038249
2016 2.862022
2017 3.551382
2019 3.411884
2020 2.328037
2021 2.532220
ggplot(spring_standard_dev_all_387, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 387 average spring temperatures for water years 2005-2021

spring MK & SS for 387 (non-corrected)

spring_sd_mk_387 <- mk.test(spring_standard_dev_all_387$sd_2)
print(spring_sd_mk_387)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_387$sd_2
## z = -1.5213, n = 28, p-value = 0.1282
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -78.0000000 2562.0000000   -0.2063492
spring_sd_sens_387 <- sens.slope(spring_standard_dev_all_387$sd_2)
print(spring_sd_sens_387)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_387$sd_2
## z = -1.5213, n = 28, p-value = 0.1282
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.046156362  0.003850971
## sample estimates:
## Sen's slope 
## -0.01808539

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_387 <- standard_dev_387 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_387 <- fall_standard_dev_all_387 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_387 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1991 3.250640
1992 3.368566
1995 2.844761
1996 3.229392
1997 3.309741
1998 3.099630
1999 2.282400
2000 2.716440
2001 2.570654
2002 2.408113
2003 2.881566
2004 3.270957
2005 2.022543
2006 2.707755
2007 2.237549
2008 2.543531
2009 2.629509
2010 3.111604
2011 2.302980
2012 2.616355
2013 2.502851
2014 2.877248
2015 2.191316
2016 2.358502
2017 2.862417
2019 2.689551
2020 3.600266
2021 2.738919
ggplot(fall_standard_dev_all_387, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 387 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 387 (non-corrected)

fall_sd_mk_387 <- mk.test(fall_standard_dev_all_387$sd_2)
print(fall_sd_mk_387)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_387$sd_2
## z = -1.4422, n = 28, p-value = 0.1492
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -74.0000000 2562.0000000   -0.1957672
fall_sd_sens_387 <- sens.slope(fall_standard_dev_all_387$sd_2)
print(fall_sd_sens_387)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_387$sd_2
## z = -1.4422, n = 28, p-value = 0.1492
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.037871544  0.007356878
## sample estimates:
## Sen's slope 
## -0.01641296

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_387_ad <- standard_dev_387_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_387_ad <- spring_standard_dev_all_387_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_387_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1991 3.343429
1992 2.448467
1995 2.757349
1996 4.287416
1997 3.363092
1998 3.356769
1999 3.044087
2000 3.004689
2001 3.107880
2002 2.462350
2003 3.095093
2004 2.609165
2005 3.031012
2006 2.423816
2007 2.956572
2008 2.861709
2009 2.897908
2010 3.282356
2011 3.490719
2012 2.893409
2013 2.878731
2014 3.387178
2015 2.976586
2016 2.826885
2017 3.510161
2019 3.348094
2020 2.361594
2021 2.509770
ggplot(spring_standard_dev_all_387_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 387 average spring temperatures for water years 1986-2021

spring MK & SS 387 (corrected)

spring_sd_mk_387_ad <- mk.test(spring_standard_dev_all_387_ad$sd_2)
print(spring_sd_mk_387_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_387_ad$sd_2
## z = -0.7705, n = 28, p-value = 0.441
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -40.0000000 2562.0000000   -0.1058201
spring_sd_sens_387_ad <- sens.slope(spring_standard_dev_all_387_ad$sd_2)
print(spring_sd_sens_387_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_387_ad$sd_2
## z = -0.7705, n = 28, p-value = 0.441
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02784506  0.01413027
## sample estimates:
##  Sen's slope 
## -0.008073558

Fall

fall_standard_dev_all_387_ad <- standard_dev_387_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_387_ad <- fall_standard_dev_all_387_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_387_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1991 2.989530
1992 3.105920
1995 2.550847
1996 2.983762
1997 2.974194
1998 2.779159
1999 2.097421
2000 2.498604
2001 2.282042
2002 2.212659
2003 2.600233
2004 3.298969
2005 2.061475
2006 2.636074
2007 2.267358
2008 2.495677
2009 2.584034
2010 3.168297
2011 2.307265
2012 2.627390
2013 2.488791
2014 2.913911
2015 2.145959
2016 2.315939
2017 2.802362
2019 2.719518
2020 3.648234
2021 2.734709
ggplot(fall_standard_dev_all_387_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 387 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 387 (corrected)

fall_sd_mk_387_ad <- mk.test(fall_standard_dev_all_387_ad$sd_2)
print(fall_sd_mk_387_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_387_ad$sd_2
## z = -0.17781, n = 28, p-value = 0.8589
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -10.00000000 2562.00000000   -0.02645503
fall_sd_sens_387_ad <- sens.slope(fall_standard_dev_all_387_ad$sd_2)
print(fall_sd_sens_387_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_387_ad$sd_2
## z = -0.17781, n = 28, p-value = 0.8589
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02362405  0.01910867
## sample estimates:
##  Sen's slope 
## -0.001971535

Cumbres Trestle 431

Oyler -> Morrisey 6/8/2005

snotel_431 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "431")
#str(snotel_431) # check the date, usually a character.  

snotel_431$Date <- as.Date(snotel_431$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_431_clean <- snotel_431 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_431_clean <- snotel_431_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_431_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_431_clean <- snotel_431_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_min > -40) %>% 
  filter(temperature_min < 25)
ggplot(snotel_431_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
snotel_431_cull_count <- snotel_431_clean %>% 
  filter(temperature_min > -40) %>% 
  count(waterYear)

snotel_431_cull_count
## # A tibble: 36 x 2
## # Groups:   waterYear [36]
##    waterYear     n
##        <dbl> <int>
##  1      1987     1
##  2      1988   341
##  3      1989   364
##  4      1990   348
##  5      1991   341
##  6      1992   312
##  7      1993   356
##  8      1994   317
##  9      1995   364
## 10      1996   364
## # ... with 26 more rows
# filtering for too few observations in a year
snotel_431_cull_count_days <- snotel_431_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_431_cull_count_days
## # A tibble: 7 x 2
## # Groups:   waterYear [7]
##   waterYear     n
##       <dbl> <int>
## 1      1987     1
## 2      1988   341
## 3      1990   348
## 4      1991   341
## 5      1992   312
## 6      1994   317
## 7      2014   288

1987, 1988, 1990, 1991, 1992, 1994, 2014 need to be culled.

snotel_431_clean_culled <- snotel_431_clean %>% 
  filter(waterYear != "1987" & waterYear != "1988" & waterYear != "1990" & waterYear != "1991" & waterYear != "1992" & waterYear != "1994" & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)
ggplot(snotel_431_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_431_xts <- xts(snotel_431_clean_culled$temperature_mean, order.by = snotel_431_clean_culled$Date)

dygraph(temp_431_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
snotel_431_clean_culled <- snotel_431_clean_culled %>% 
  filter(temperature_mean < 20)

temp_431_xts <- xts(snotel_431_clean_culled$temperature_mean, order.by = snotel_431_clean_culled$Date)

dygraph(temp_431_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Cumbres Trestle 431

Oyler -> Morrisey 6/8/2005

snotel_431_adjusted <- snotel_431_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2005-06-08", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

431 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_431 <- snotel_431_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_431 <- yearly_wy_aver_431 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(temperature_mean))

#average mean temperature by day for the period of record:

daily_wy_aver_431 <- daily_wy_aver_431 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_431$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_431 <-daily_wy_aver_431 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_431$date_temp <- signif(daily_wy_aver2_431$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_431, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

431 SD

standard_dev_431 <- daily_wy_aver_431 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_431 <- standard_dev_431 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_431 <- standard_dev_all_431 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_431 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 3.461475
1993 2.948998
1995 3.422170
1996 3.427639
1997 3.387657
1998 3.293228
1999 3.378178
2000 3.301047
2001 3.320669
2002 3.411454
2003 3.175412
2004 3.408413
2005 3.080972
2006 3.339172
2007 3.210695
2008 3.326265
2009 3.218093
2010 3.043811
2011 3.489052
2012 2.993331
2013 3.514482
2015 3.229094
2016 3.205754
2017 3.395324
2018 3.083196
2019 3.064569
2020 3.039085
2021 3.115515
2022 3.185240
ggplot(standard_dev_all_431, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 431 average temperatures for water years 2005-2021

MK & SS for 431 (non-corrected)

sd_mk_431 <- mk.test(standard_dev_all_431$sd_2)
print(sd_mk_431)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_431$sd_2
## z = -2.3448, n = 29, p-value = 0.01904
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -126.0000000 2842.0000000   -0.3103448
sd_sens_431 <- sens.slope(standard_dev_all_431$sd_2)
print(sd_sens_431)
## 
##  Sen's slope
## 
## data:  standard_dev_all_431$sd_2
## z = -2.3448, n = 29, p-value = 0.01904
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01611890 -0.00181818
## sample estimates:
## Sen's slope 
## -0.01021199

Corrected

431 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_431_ad <- snotel_431_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_431_ad <- yearly_wy_aver_431_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_431_ad <- daily_wy_aver_431_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_431_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_431_ad <-daily_wy_aver_431_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_431_ad$date_temp_ad <- signif(daily_wy_aver2_431_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_431_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

431 SS (corrected)

standard_dev_431_ad <- daily_wy_aver_431_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_431_ad <- standard_dev_431_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_431_ad <- standard_dev_all_431_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_431_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 3.276136
1993 2.776218
1995 3.253735
1996 3.247730
1997 3.207047
1998 3.057162
1999 3.265826
2000 3.103557
2001 3.085735
2002 3.133544
2003 2.937606
2004 3.229313
2005 2.896438
2006 3.291536
2007 3.214913
2008 3.342137
2009 3.166973
2010 3.099999
2011 3.504723
2012 3.019459
2013 3.545426
2015 3.166623
2016 3.190939
2017 3.335950
2018 3.021367
2019 3.070185
2020 3.054315
2021 3.128238
2022 3.157085
ggplot(standard_dev_all_431_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 431 average temperatures for water years 1986-2021

MK & SS 431 (corrected)

sd_mk_431_ad <- mk.test(standard_dev_all_431_ad$sd_2)
print(sd_mk_431_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_431_ad$sd_2
## z = -0.31889, n = 29, p-value = 0.7498
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -18.00000000 2842.00000000   -0.04433498
sd_sens_431_ad <- sens.slope(standard_dev_all_431_ad$sd_2)
print(sd_sens_431_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_431_ad$sd_2
## z = -0.31889, n = 29, p-value = 0.7498
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.006517214  0.007869194
## sample estimates:
##  Sen's slope 
## -0.001540485

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_431 <- standard_dev_431 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_431 <- summer_standard_dev_all_431 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_431 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 2.103828
1993 2.104598
1995 2.613841
1996 1.823808
1997 2.017153
1998 2.146990
1999 1.934252
2000 1.673668
2001 2.034521
2002 2.047044
2003 2.354114
2004 2.147493
2005 1.822526
2006 1.875217
2007 1.945566
2008 1.841490
2009 1.827530
2010 1.981385
2011 1.505585
2012 1.709286
2013 1.920255
2015 1.920191
2016 2.206616
2017 1.637462
2018 1.791173
2019 1.947374
2020 1.894377
2021 2.305051
2022 2.204440
ggplot(summer_standard_dev_all_431, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 431 average summer temperatures for water years 2005-2021

summer MK & SS for 431 (non-corrected)

summer_sd_mk_431 <- mk.test(summer_standard_dev_all_431$sd_2)
print(summer_sd_mk_431)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_431$sd_2
## z = -1.0317, n = 29, p-value = 0.3022
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##           S        varS         tau 
##  -56.000000 2842.000000   -0.137931
summer_sd_sens_431 <- sens.slope(summer_standard_dev_all_431$sd_2)
print(summer_sd_sens_431)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_431$sd_2
## z = -1.0317, n = 29, p-value = 0.3022
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.015969401  0.005140882
## sample estimates:
##  Sen's slope 
## -0.006430174

Winter

winter_standard_dev_all_431 <- standard_dev_431 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_431 <- winter_standard_dev_all_431 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_431 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 4.270826
1993 3.558183
1995 3.893094
1996 3.921610
1997 3.934682
1998 3.684018
1999 3.665677
2000 3.990225
2001 3.878428
2002 4.008337
2003 3.491354
2004 4.216492
2005 3.716249
2006 4.108147
2007 4.118269
2008 4.236792
2009 3.805201
2010 3.286912
2011 4.452406
2012 3.552147
2013 4.616215
2015 3.903798
2016 4.000929
2017 3.832817
2018 3.777995
2019 3.601087
2020 3.234365
2021 3.567427
2022 3.689902
ggplot(winter_standard_dev_all_431, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 431 average winter temperatures for water years 2005-2021

winter MK & SS for 431 (non-corrected)

winter_sd_mk_431 <- mk.test(winter_standard_dev_all_431$sd_2)
print(winter_sd_mk_431)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_431$sd_2
## z = -0.91915, n = 29, p-value = 0.358
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -50.0000000 2842.0000000   -0.1231527
winter_sd_sens_431 <- sens.slope(winter_standard_dev_all_431$sd_2)
print(winter_sd_sens_431)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_431$sd_2
## z = -0.91915, n = 29, p-value = 0.358
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.022023193  0.009831763
## sample estimates:
##  Sen's slope 
## -0.007824722

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_431_ad <- standard_dev_431_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_431_ad <- summer_standard_dev_all_431_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_431_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 1.866863
1993 1.879218
1995 2.342301
1996 1.639152
1997 1.814858
1998 1.919707
1999 1.735688
2000 1.510018
2001 1.834230
2002 1.850106
2003 2.091658
2004 1.935870
2005 1.779789
2006 1.849514
2007 1.958464
2008 1.845403
2009 1.850262
2010 1.961802
2011 1.510337
2012 1.683891
2013 1.886707
2015 1.902417
2016 2.204170
2017 1.620017
2018 1.772214
2019 1.959031
2020 1.887636
2021 2.282864
2022 2.183940
ggplot(summer_standard_dev_all_431_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 431 average summer temperatures for water years 1986-2021

summer MK & SS 431 (corrected)

summer_sd_mk_431_ad <- mk.test(summer_standard_dev_all_431_ad$sd_2)
print(summer_sd_mk_431_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_431_ad$sd_2
## z = 1.2943, n = 29, p-value = 0.1956
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   70.0000000 2842.0000000    0.1724138
summer_sd_sens_431_ad <- sens.slope(summer_standard_dev_all_431_ad$sd_2)
print(summer_sd_sens_431_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_431_ad$sd_2
## z = 1.2943, n = 29, p-value = 0.1956
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.002475303  0.014153638
## sample estimates:
## Sen's slope 
## 0.004340592

Winter

winter_standard_dev_all_431_ad <- standard_dev_431_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_431_ad <- winter_standard_dev_all_431_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_431_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 4.121126
1993 3.447581
1995 3.757085
1996 3.767330
1997 3.787932
1998 3.553796
1999 3.524564
2000 3.814411
2001 3.759445
2002 3.837012
2003 3.368838
2004 4.063186
2005 3.602862
2006 4.096465
2007 4.128021
2008 4.251234
2009 3.796549
2010 3.289035
2011 4.452295
2012 3.552065
2013 4.622279
2015 3.904874
2016 3.994623
2017 3.840897
2018 3.765096
2019 3.585795
2020 3.234714
2021 3.556911
2022 3.686172
ggplot(winter_standard_dev_all_431_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 431 average winter temperatures for water years 1986-2021

winter MK & SS 431 (corrected)

winter_sd_mk_431_ad <- mk.test(winter_standard_dev_all_431_ad$sd_2)
print(winter_sd_mk_431_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_431_ad$sd_2
## z = 0.13131, n = 29, p-value = 0.8955
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 8.000000e+00 2.842000e+03 1.970443e-02
winter_sd_sens_431_ad <- sens.slope(winter_standard_dev_all_431_ad$sd_2)
print(winter_sd_sens_431_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_431_ad$sd_2
## z = 0.13131, n = 29, p-value = 0.8955
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01519443  0.01411645
## sample estimates:
##  Sen's slope 
## 0.0003786793

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_431 <- standard_dev_431 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_431 <- spring_standard_dev_all_431 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_431 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 3.269774
1993 2.452300
1995 3.246883
1996 3.732203
1997 3.175837
1998 3.282564
1999 3.606382
2000 3.626528
2001 3.272787
2002 2.730514
2003 3.521057
2004 2.690825
2005 2.994577
2006 2.532331
2007 2.873425
2008 3.059845
2009 3.230629
2010 3.308819
2011 3.614975
2012 3.128677
2013 3.058907
2015 2.876029
2016 2.940925
2017 3.816191
2018 2.659764
2019 3.430881
2020 2.477693
2021 2.799274
2022 3.189234
ggplot(spring_standard_dev_all_431, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 431 average spring temperatures for water years 2005-2021

spring MK & SS for 431 (non-corrected)

spring_sd_mk_431 <- mk.test(spring_standard_dev_all_431$sd_2)
print(spring_sd_mk_431)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_431$sd_2
## z = -1.0692, n = 29, p-value = 0.285
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -58.0000000 2842.0000000   -0.1428571
spring_sd_sens_431 <- sens.slope(spring_standard_dev_all_431$sd_2)
print(spring_sd_sens_431)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_431$sd_2
## z = -1.0692, n = 29, p-value = 0.285
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.030241677  0.009299696
## sample estimates:
## Sen's slope 
## -0.01093163

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_431 <- standard_dev_431 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_431 <- fall_standard_dev_all_431 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_431 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 2.089148
1993 2.504282
1995 2.990227
1996 3.359332
1997 3.706676
1998 3.486675
1999 2.818904
2000 2.834598
2001 2.432460
2002 2.600487
2003 2.614290
2004 3.256090
2005 2.788602
2006 2.949692
2007 2.273212
2008 2.730817
2009 2.807315
2010 3.350997
2011 2.384236
2012 2.574448
2013 2.400334
2015 2.137696
2016 2.114198
2017 3.106456
2018 2.563025
2019 2.470592
2020 3.877675
2021 2.974366
2022 2.923872
ggplot(fall_standard_dev_all_431, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 431 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 431 (non-corrected)

fall_sd_mk_431 <- mk.test(fall_standard_dev_all_431$sd_2)
print(fall_sd_mk_431)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_431$sd_2
## z = -0.65653, n = 29, p-value = 0.5115
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -36.00000000 2842.00000000   -0.08866995
fall_sd_sens_431 <- sens.slope(fall_standard_dev_all_431$sd_2)
print(fall_sd_sens_431)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_431$sd_2
## z = -0.65653, n = 29, p-value = 0.5115
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03112589  0.01639377
## sample estimates:
##  Sen's slope 
## -0.007589982

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_431_ad <- standard_dev_431_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_431_ad <- spring_standard_dev_all_431_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_431_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 3.018818
1993 2.249119
1995 3.026977
1996 3.398212
1997 2.924662
1998 2.997277
1999 3.335184
2000 3.300063
2001 2.995071
2002 2.512968
2003 3.228045
2004 2.471624
2005 2.729425
2006 2.529852
2007 2.851362
2008 3.059087
2009 3.249684
2010 3.324557
2011 3.594701
2012 3.113318
2013 3.060803
2015 2.816034
2016 2.921787
2017 3.789308
2018 2.661167
2019 3.369125
2020 2.485504
2021 2.770085
2022 3.187320
ggplot(spring_standard_dev_all_431_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 431 average spring temperatures for water years 1986-2021

spring MK & SS 431 (corrected)

spring_sd_mk_431_ad <- mk.test(spring_standard_dev_all_431_ad$sd_2)
print(spring_sd_mk_431_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_431_ad$sd_2
## z = 0.24385, n = 29, p-value = 0.8073
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 1.400000e+01 2.842000e+03 3.448276e-02
spring_sd_sens_431_ad <- sens.slope(spring_standard_dev_all_431_ad$sd_2)
print(spring_sd_sens_431_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_431_ad$sd_2
## z = 0.24385, n = 29, p-value = 0.8073
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.0162128  0.0209227
## sample estimates:
## Sen's slope 
## 0.002577331

Fall

fall_standard_dev_all_431_ad <- standard_dev_431_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_431_ad <- fall_standard_dev_all_431_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_431_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 1.976956
1993 2.353569
1995 2.703765
1996 3.129570
1997 3.373137
1998 3.157189
1999 2.607532
2000 2.587964
2001 2.168247
2002 2.398993
2003 2.386916
2004 3.023248
2005 2.415656
2006 2.872842
2007 2.315883
2008 2.683026
2009 2.761306
2010 3.423943
2011 2.368212
2012 2.588450
2013 2.397732
2015 2.090366
2016 2.078373
2017 3.032984
2018 2.536845
2019 2.520373
2020 3.918083
2021 2.974196
2022 2.952361
ggplot(fall_standard_dev_all_431_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 431 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 431 (corrected)

fall_sd_mk_431_ad <- mk.test(fall_standard_dev_all_431_ad$sd_2)
print(fall_sd_mk_431_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_431_ad$sd_2
## z = 0.39392, n = 29, p-value = 0.6936
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 2.200000e+01 2.842000e+03 5.418719e-02
fall_sd_sens_431_ad <- sens.slope(fall_standard_dev_all_431_ad$sd_2)
print(fall_sd_sens_431_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_431_ad$sd_2
## z = 0.39392, n = 29, p-value = 0.6936
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01734529  0.02391146
## sample estimates:
## Sen's slope 
## 0.005477328

Idarado 538

Morrisey 7/12/2004

snotel_538 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "538")
#str(snotel_538) # check the date, usually a character.  

snotel_538$Date <- as.Date(snotel_538$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_538_clean <- snotel_538 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_538_clean <- snotel_538_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_538_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_538_clean <- snotel_538_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40)# %>% 
  #filter(temperature_min < 25)
ggplot(snotel_538_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
snotel_538_cull_count <- snotel_538_clean %>% 
  filter(temperature_min > -40) %>% 
  count(waterYear)

snotel_538_cull_count
## # A tibble: 36 x 2
## # Groups:   waterYear [36]
##    waterYear     n
##        <dbl> <int>
##  1      1987   355
##  2      1988   366
##  3      1989   364
##  4      1990   365
##  5      1991   337
##  6      1992   358
##  7      1993   346
##  8      1994   351
##  9      1995   364
## 10      1996   365
## # ... with 26 more rows
# filtering for too few observations in a year
snotel_538_cull_count_days <- snotel_538_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_538_cull_count_days
## # A tibble: 2 x 2
## # Groups:   waterYear [2]
##   waterYear     n
##       <dbl> <int>
## 1      1991   337
## 2      1993   346

1991 and 1993 need to be culled.

snotel_538_clean_culled <- snotel_538_clean %>% 
  filter(waterYear != "1991" & waterYear != "1993") # & waterYear != "1990" & waterYear != "1991" & waterYear != "1992" & waterYear != "1994" & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)
ggplot(snotel_538_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_538_xts <- xts(snotel_538_clean_culled$temperature_mean, order.by = snotel_538_clean_culled$Date)

dygraph(temp_538_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
snotel_538_clean_culled <- snotel_538_clean_culled %>% 
  filter(temperature_mean < 20)

temp_538_xts <- xts(snotel_538_clean_culled$temperature_mean, order.by = snotel_538_clean_culled$Date)

dygraph(temp_538_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Idarado 538

Morrisey 7/12/2004

snotel_538_adjusted <- snotel_538_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2004-07-12", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

538 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_538 <- snotel_538_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_538 <- yearly_wy_aver_538 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(temperature_mean))

#average mean temperature by day for the period of record:

daily_wy_aver_538 <- daily_wy_aver_538 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_538$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_538 <-daily_wy_aver_538 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_538$date_temp <- signif(daily_wy_aver2_538$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_538, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

538 SD

standard_dev_538 <- daily_wy_aver_538 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_538 <- standard_dev_538 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_538 <- standard_dev_all_538 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_538 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.300536
1988 3.603048
1989 4.004101
1990 3.500260
1992 3.357355
1994 6.000607
1995 3.387101
1996 3.492877
1997 3.477992
1998 3.340924
1999 3.384344
2000 3.404278
2001 3.278389
2002 3.481281
2003 3.146159
2004 3.614214
2005 3.210792
2006 3.467313
2007 3.360272
2008 3.442579
2009 3.291084
2010 3.190995
2011 3.667537
2012 2.995992
2013 3.705839
2014 3.154671
2015 3.328834
2016 3.189214
2017 3.717989
2018 3.159176
2019 3.209353
2020 3.328941
2021 3.208157
2022 3.331097
ggplot(standard_dev_all_538, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 538 average temperatures for water years 2005-2021

MK & SS for 538 (non-corrected)

sd_mk_538 <- mk.test(standard_dev_all_538$sd_2)
print(sd_mk_538)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_538$sd_2
## z = -2.3719, n = 34, p-value = 0.0177
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -161.0000000 4550.3333333   -0.2869875
sd_sens_538 <- sens.slope(standard_dev_all_538$sd_2)
print(sd_sens_538)
## 
##  Sen's slope
## 
## data:  standard_dev_all_538$sd_2
## z = -2.3719, n = 34, p-value = 0.0177
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.015183137 -0.001845521
## sample estimates:
##  Sen's slope 
## -0.008286543

Corrected

538 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_538_ad <- snotel_538_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_538_ad <- yearly_wy_aver_538_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_538_ad <- daily_wy_aver_538_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_538_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_538_ad <-daily_wy_aver_538_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_538_ad$date_temp_ad <- signif(daily_wy_aver2_538_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_538_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

538 SS (corrected)

standard_dev_538_ad <- daily_wy_aver_538_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_538_ad <- standard_dev_538_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_538_ad <- standard_dev_all_538_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_538_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.122332
1988 3.385850
1989 3.796718
1990 3.295889
1992 3.187723
1994 5.720548
1995 3.218083
1996 3.311027
1997 3.328453
1998 3.126275
1999 3.269648
2000 3.225281
2001 3.072468
2002 3.228122
2003 2.933569
2004 3.499935
2005 3.175098
2006 3.437140
2007 3.367022
2008 3.459025
2009 3.233642
2010 3.218829
2011 3.660216
2012 3.007388
2013 3.736638
2014 3.135131
2015 3.257273
2016 3.173962
2017 3.658447
2018 3.116806
2019 3.209130
2020 3.344087
2021 3.227904
2022 3.317989
ggplot(standard_dev_all_538_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 538 average temperatures for water years 1986-2021

MK & SS 538 (corrected)

sd_mk_538_ad <- mk.test(standard_dev_all_538_ad$sd_2)
print(sd_mk_538_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_538_ad$sd_2
## z = -0.23719, n = 34, p-value = 0.8125
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -17.00000000 4550.33333333   -0.03030303
sd_sens_538_ad <- sens.slope(standard_dev_all_538_ad$sd_2)
print(sd_sens_538_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_538_ad$sd_2
## z = -0.23719, n = 34, p-value = 0.8125
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.008010924  0.005940325
## sample estimates:
##   Sen's slope 
## -0.0005982823

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_538 <- standard_dev_538 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_538 <- summer_standard_dev_all_538 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_538 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 1.994580
1988 1.827252
1989 2.583132
1990 2.604834
1992 2.252331
1994 1.740320
1995 2.863055
1996 1.639070
1997 1.635238
1998 2.169459
1999 1.809371
2000 1.695032
2001 2.103619
2002 2.253761
2003 2.031587
2004 2.382239
2005 2.056503
2006 1.949372
2007 1.691745
2008 1.855019
2009 1.806935
2010 2.045027
2011 1.614941
2012 1.621441
2013 1.915717
2014 1.529534
2015 1.969473
2016 1.950362
2017 1.666356
2018 1.473470
2019 1.921338
2020 2.098320
2021 2.288650
2022 2.039629
ggplot(summer_standard_dev_all_538, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 538 average summer temperatures for water years 2005-2021

summer MK & SS for 538 (non-corrected)

summer_sd_mk_538 <- mk.test(summer_standard_dev_all_538$sd_2)
print(summer_sd_mk_538)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_538$sd_2
## z = -1.4528, n = 34, p-value = 0.1463
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -99.0000000 4550.3333333   -0.1764706
summer_sd_sens_538 <- sens.slope(summer_standard_dev_all_538$sd_2)
print(summer_sd_sens_538)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_538$sd_2
## z = -1.4528, n = 34, p-value = 0.1463
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.019843179  0.003846278
## sample estimates:
##  Sen's slope 
## -0.009355047

Winter

winter_standard_dev_all_538 <- standard_dev_538 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_538 <- winter_standard_dev_all_538 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_538 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 4.124247
1988 4.488140
1989 5.045192
1990 4.287509
1992 3.533977
1994 5.690036
1995 4.024120
1996 4.063752
1997 4.352575
1998 3.976570
1999 4.051663
2000 4.296414
2001 3.965797
2002 4.189290
2003 3.696997
2004 4.497960
2005 4.119077
2006 4.392518
2007 4.443112
2008 4.353320
2009 4.009615
2010 3.571633
2011 4.825704
2012 3.733881
2013 4.823652
2014 3.721317
2015 3.936866
2016 4.092560
2017 4.432723
2018 4.019448
2019 3.922151
2020 3.770983
2021 3.755485
2022 4.094462
ggplot(winter_standard_dev_all_538, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 538 average winter temperatures for water years 2005-2021

winter MK & SS for 538 (non-corrected)

winter_sd_mk_538 <- mk.test(winter_standard_dev_all_538$sd_2)
print(winter_sd_mk_538)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_538$sd_2
## z = -1.5417, n = 34, p-value = 0.1231
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -105.0000000 4550.3333333   -0.1871658
winter_sd_sens_538 <- sens.slope(winter_standard_dev_all_538$sd_2)
print(winter_sd_sens_538)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_538$sd_2
## z = -1.5417, n = 34, p-value = 0.1231
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.023243347  0.003004157
## sample estimates:
## Sen's slope 
## -0.01031001

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_538_ad <- standard_dev_538_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_538_ad <- summer_standard_dev_all_538_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_538_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 1.795155
1988 1.639900
1989 2.295653
1990 2.348784
1992 2.019398
1994 1.569099
1995 2.579997
1996 1.480124
1997 1.469210
1998 1.934393
1999 1.624060
2000 1.536330
2001 1.898639
2002 2.021946
2003 1.798787
2004 2.237138
2005 2.084540
2006 1.930143
2007 1.700601
2008 1.861599
2009 1.828980
2010 2.034926
2011 1.612927
2012 1.603363
2013 1.900720
2014 1.532544
2015 1.963651
2016 1.948426
2017 1.646652
2018 1.458556
2019 1.928134
2020 2.093314
2021 2.257585
2022 2.013868
ggplot(summer_standard_dev_all_538_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 538 average summer temperatures for water years 1986-2021

summer MK & SS 538 (corrected)

summer_sd_mk_538_ad <- mk.test(summer_standard_dev_all_538_ad$sd_2)
print(summer_sd_mk_538_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_538_ad$sd_2
## z = 0.14824, n = 34, p-value = 0.8821
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 1.100000e+01 4.550333e+03 1.960784e-02
summer_sd_sens_538_ad <- sens.slope(summer_standard_dev_all_538_ad$sd_2)
print(summer_sd_sens_538_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_538_ad$sd_2
## z = 0.14824, n = 34, p-value = 0.8821
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01117185  0.01132001
## sample estimates:
##  Sen's slope 
## 0.0007796062

Winter

winter_standard_dev_all_538_ad <- standard_dev_538_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_538_ad <- winter_standard_dev_all_538_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_538_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.984437
1988 4.336851
1989 4.881516
1990 4.144880
1992 3.415669
1994 5.582530
1995 3.866332
1996 3.915969
1997 4.208700
1998 3.851137
1999 3.901089
2000 4.132050
2001 3.850486
2002 4.041719
2003 3.579719
2004 4.349077
2005 4.101906
2006 4.388051
2007 4.451970
2008 4.362841
2009 4.000163
2010 3.573670
2011 4.822841
2012 3.733055
2013 4.827254
2014 3.717743
2015 3.939429
2016 4.088304
2017 4.435332
2018 4.012068
2019 3.912252
2020 3.771870
2021 3.754359
2022 4.089228
ggplot(winter_standard_dev_all_538_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 538 average winter temperatures for water years 1986-2021

winter MK & SS 538 (corrected)

winter_sd_mk_538_ad <- mk.test(winter_standard_dev_all_538_ad$sd_2)
print(winter_sd_mk_538_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_538_ad$sd_2
## z = -0.62263, n = 34, p-value = 0.5335
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -43.00000000 4550.33333333   -0.07664884
winter_sd_sens_538_ad <- sens.slope(winter_standard_dev_all_538_ad$sd_2)
print(winter_sd_sens_538_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_538_ad$sd_2
## z = -0.62263, n = 34, p-value = 0.5335
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.017378171  0.009504841
## sample estimates:
##  Sen's slope 
## -0.004207725

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_538 <- standard_dev_538 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_538 <- spring_standard_dev_all_538 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_538 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.051006
1988 3.691013
1989 3.746770
1990 2.799596
1992 2.844332
1994 3.025670
1995 2.839473
1996 3.866208
1997 3.372040
1998 2.941213
1999 3.242243
2000 3.337650
2001 3.145757
2002 2.475493
2003 3.338024
2004 2.572939
2005 2.872881
2006 2.655141
2007 2.839452
2008 3.169045
2009 2.952123
2010 3.634283
2011 3.513351
2012 2.957848
2013 3.385650
2014 3.490986
2015 2.728524
2016 2.600440
2017 3.558654
2018 2.881026
2019 3.204531
2020 2.677413
2021 2.624393
2022 3.359117
ggplot(spring_standard_dev_all_538, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 538 average spring temperatures for water years 2005-2021

spring MK & SS for 538 (non-corrected)

spring_sd_mk_538 <- mk.test(spring_standard_dev_all_538$sd_2)
print(spring_sd_mk_538)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_538$sd_2
## z = -0.68192, n = 34, p-value = 0.4953
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -47.00000000 4550.33333333   -0.08377897
spring_sd_sens_538 <- sens.slope(spring_standard_dev_all_538$sd_2)
print(spring_sd_sens_538)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_538$sd_2
## z = -0.68192, n = 34, p-value = 0.4953
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.019328632  0.009336716
## sample estimates:
##  Sen's slope 
## -0.006026834

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_538 <- standard_dev_538 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_538 <- fall_standard_dev_all_538 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_538 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.541700
1988 2.487556
1989 2.201963
1990 2.979005
1992 4.001905
1994 7.962149
1995 2.457520
1996 3.488927
1997 3.125136
1998 3.196277
1999 2.727091
2000 2.776462
2001 2.125042
2002 2.666311
2003 2.372274
2004 3.127973
2005 2.027010
2006 3.097495
2007 2.455439
2008 2.843967
2009 2.700336
2010 3.153432
2011 2.308335
2012 2.387680
2013 2.532440
2014 2.862789
2015 2.363087
2016 2.331620
2017 3.392792
2018 2.597774
2019 2.414563
2020 4.009187
2021 3.265959
2022 2.612137
ggplot(fall_standard_dev_all_538, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 538 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 538 (non-corrected)

fall_sd_mk_538 <- mk.test(fall_standard_dev_all_538$sd_2)
print(fall_sd_mk_538)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_538$sd_2
## z = -0.38544, n = 34, p-value = 0.6999
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -27.00000000 4550.33333333   -0.04812834
fall_sd_sens_538 <- sens.slope(fall_standard_dev_all_538$sd_2)
print(fall_sd_sens_538)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_538$sd_2
## z = -0.38544, n = 34, p-value = 0.6999
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02531789  0.01377184
## sample estimates:
##  Sen's slope 
## -0.004237878

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_538_ad <- standard_dev_538_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_538_ad <- spring_standard_dev_all_538_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_538_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.826944
1988 3.399154
1989 3.452215
1990 2.595760
1992 2.642980
1994 2.765548
1995 2.647953
1996 3.546192
1997 3.134852
1998 2.681226
1999 2.994392
2000 3.045129
2001 2.891382
2002 2.273452
2003 3.047331
2004 2.373504
2005 2.895601
2006 2.645706
2007 2.822723
2008 3.177797
2009 2.985665
2010 3.642928
2011 3.507137
2012 2.944906
2013 3.398493
2014 3.497508
2015 2.678454
2016 2.581695
2017 3.535788
2018 2.885340
2019 3.153456
2020 2.696032
2021 2.603130
2022 3.362201
ggplot(spring_standard_dev_all_538_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 538 average spring temperatures for water years 1986-2021

spring MK & SS 538 (corrected)

spring_sd_mk_538_ad <- mk.test(spring_standard_dev_all_538_ad$sd_2)
print(spring_sd_mk_538_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_538_ad$sd_2
## z = 0.59298, n = 34, p-value = 0.5532
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 4.100000e+01 4.550333e+03 7.308378e-02
spring_sd_sens_538_ad <- sens.slope(spring_standard_dev_all_538_ad$sd_2)
print(spring_sd_sens_538_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_538_ad$sd_2
## z = 0.59298, n = 34, p-value = 0.5532
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01028157  0.01996955
## sample estimates:
## Sen's slope 
## 0.003638692

Fall

fall_standard_dev_all_538_ad <- standard_dev_538_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_538_ad <- fall_standard_dev_all_538_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_538_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.409152
1988 2.343193
1989 2.071350
1990 2.711552
1992 3.710626
1994 7.537652
1995 2.242053
1996 3.253013
1997 2.859367
1998 2.913600
1999 2.565864
2000 2.563988
2001 1.943968
2002 2.491856
2003 2.192894
2004 3.233931
2005 2.032995
2006 3.015361
2007 2.494493
2008 2.812284
2009 2.669163
2010 3.195004
2011 2.279548
2012 2.388125
2013 2.532700
2014 2.896835
2015 2.305203
2016 2.267934
2017 3.326095
2018 2.567956
2019 2.447464
2020 4.042465
2021 3.264545
2022 2.655709
ggplot(fall_standard_dev_all_538_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 538 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 538 (corrected)

fall_sd_mk_538_ad <- mk.test(fall_standard_dev_all_538_ad$sd_2)
print(fall_sd_mk_538_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_538_ad$sd_2
## z = 0.53368, n = 34, p-value = 0.5936
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 3.700000e+01 4.550333e+03 6.595365e-02
fall_sd_sens_538_ad <- sens.slope(fall_standard_dev_all_538_ad$sd_2)
print(fall_sd_sens_538_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_538_ad$sd_2
## z = 0.53368, n = 34, p-value = 0.5936
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01593147  0.02306841
## sample estimates:
## Sen's slope 
## 0.005147839

Lone Cone 589

Oyler -> Morrisey 6/22/2005

snotel_589 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "589")
#str(snotel_589) # check the date, usually a character.  

snotel_589$Date <- as.Date(snotel_589$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_589_clean <- snotel_589 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_589_clean <- snotel_589_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_589_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_589_clean <- snotel_589_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40)# %>% 
  #filter(temperature_min < 25)
ggplot(snotel_589_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
snotel_589_cull_count <- snotel_589_clean %>% 
  filter(temperature_min > -40) %>% 
  count(waterYear)

snotel_589_cull_count
## # A tibble: 37 x 2
## # Groups:   waterYear [37]
##    waterYear     n
##        <dbl> <int>
##  1      1986     1
##  2      1987   358
##  3      1988   366
##  4      1989   362
##  5      1990   365
##  6      1991   359
##  7      1992   366
##  8      1993   350
##  9      1994   337
## 10      1995   364
## # ... with 27 more rows
# filtering for too few observations in a year
snotel_589_cull_count_days <- snotel_589_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_589_cull_count_days
## # A tibble: 10 x 2
## # Groups:   waterYear [10]
##    waterYear     n
##        <dbl> <int>
##  1      1986     1
##  2      1994   337
##  3      1997   346
##  4      2006   317
##  5      2009   314
##  6      2010   332
##  7      2011   309
##  8      2012   322
##  9      2013   331
## 10      2014   335

1986, 1994, 1997, 2006, 2009, 2010, 2011, 2012, 2013, 2014 need to be culled.

snotel_589_clean_culled <- snotel_589_clean %>% 
  filter(waterYear != "1986" & waterYear != "1994" & waterYear != "1997" & waterYear != "2006" & waterYear != "2009" & waterYear != "2010" & waterYear != "2011" & waterYear != "2012" & waterYear != "2013" & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)
ggplot(snotel_589_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_589_xts <- xts(snotel_589_clean_culled$temperature_mean, order.by = snotel_589_clean_culled$Date)

dygraph(temp_589_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
snotel_589_clean_culled <- snotel_589_clean_culled %>% 
  filter(temperature_mean < 20)

temp_589_xts <- xts(snotel_589_clean_culled$temperature_mean, order.by = snotel_589_clean_culled$Date)

dygraph(temp_589_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Lone Cone 589

Oyler -> Morrisey 6/22/2005

snotel_589_adjusted <- snotel_589_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2005-06-22", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

589 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_589 <- snotel_589_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_589 <- yearly_wy_aver_589 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(temperature_mean))

#average mean temperature by day for the period of record:

daily_wy_aver_589 <- daily_wy_aver_589 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_589$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_589 <-daily_wy_aver_589 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_589$date_temp <- signif(daily_wy_aver2_589$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_589, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

589 SD

standard_dev_589 <- daily_wy_aver_589 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_589 <- standard_dev_589 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_589 <- standard_dev_all_589 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_589 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.273069
1988 3.665269
1989 4.109813
1990 3.609939
1991 3.446213
1992 3.027857
1993 3.398055
1995 3.671336
1996 3.552167
1998 3.440666
1999 3.733465
2000 3.460883
2001 3.470977
2002 3.516969
2003 3.337633
2004 3.795404
2005 3.441278
2007 3.485016
2008 3.440359
2015 3.376488
2016 3.328499
2017 3.776952
2018 3.234846
2019 3.235625
2020 3.491035
2021 3.245196
2022 3.398843
ggplot(standard_dev_all_589, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 589 average temperatures for water years 2005-2021

MK & SS for 589 (non-corrected)

sd_mk_589 <- mk.test(standard_dev_all_589$sd_2)
print(sd_mk_589)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_589$sd_2
## z = -1.6678, n = 27, p-value = 0.09536
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -81.0000000 2301.0000000   -0.2307692
sd_sens_589 <- sens.slope(standard_dev_all_589$sd_2)
print(sd_sens_589)
## 
##  Sen's slope
## 
## data:  standard_dev_all_589$sd_2
## z = -1.6678, n = 27, p-value = 0.09536
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.018638965  0.002241063
## sample estimates:
##  Sen's slope 
## -0.009554706

Corrected

589 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_589_ad <- snotel_589_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_589_ad <- yearly_wy_aver_589_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_589_ad <- daily_wy_aver_589_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_589_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_589_ad <-daily_wy_aver_589_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_589_ad$date_temp_ad <- signif(daily_wy_aver2_589_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_589_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

589 SS (corrected)

standard_dev_589_ad <- daily_wy_aver_589_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_589_ad <- standard_dev_589_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_589_ad <- standard_dev_all_589_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_589_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.114352
1988 3.468664
1989 3.918860
1990 3.423627
1991 3.287375
1992 2.868550
1993 3.232244
1995 3.484693
1996 3.359369
1998 3.226619
1999 3.582689
2000 3.278834
2001 3.268860
2002 3.274042
2003 3.124670
2004 3.616671
2005 3.269359
2007 3.494176
2008 3.466136
2015 3.271804
2016 3.303837
2017 3.699638
2018 3.183175
2019 3.246066
2020 3.513539
2021 3.272556
2022 3.392615
ggplot(standard_dev_all_589_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 589 average temperatures for water years 1986-2021

MK & SS 589 (corrected)

sd_mk_589_ad <- mk.test(standard_dev_all_589_ad$sd_2)
print(sd_mk_589_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_589_ad$sd_2
## z = 0.25016, n = 27, p-value = 0.8025
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 1.300000e+01 2.301000e+03 3.703704e-02
sd_sens_589_ad <- sens.slope(standard_dev_all_589_ad$sd_2)
print(sd_sens_589_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_589_ad$sd_2
## z = 0.25016, n = 27, p-value = 0.8025
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.009190031  0.010676677
## sample estimates:
## Sen's slope 
## 0.000813068

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_589 <- standard_dev_589 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_589 <- summer_standard_dev_all_589 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_589 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 1.766679
1988 2.293733
1989 2.934491
1990 2.427651
1991 2.073952
1992 2.222876
1993 2.374162
1995 2.892043
1996 1.816529
1998 2.226481
1999 2.283376
2000 1.811082
2001 2.372212
2002 2.355944
2003 2.169387
2004 2.254973
2005 2.276333
2007 1.754151
2008 1.762211
2015 2.104523
2016 2.241750
2017 1.788730
2018 1.511541
2019 1.875519
2020 2.173907
2021 2.332493
2022 2.104862
ggplot(summer_standard_dev_all_589, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 589 average summer temperatures for water years 2005-2021

summer MK & SS for 589 (non-corrected)

summer_sd_mk_589 <- mk.test(summer_standard_dev_all_589$sd_2)
print(summer_sd_mk_589)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_589$sd_2
## z = -1.8345, n = 27, p-value = 0.06658
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -89.0000000 2301.0000000   -0.2535613
summer_sd_sens_589 <- sens.slope(summer_standard_dev_all_589$sd_2)
print(summer_sd_sens_589)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_589$sd_2
## z = -1.8345, n = 27, p-value = 0.06658
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.028497301  0.001050047
## sample estimates:
## Sen's slope 
## -0.01093535

Winter

winter_standard_dev_all_589 <- standard_dev_589 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_589 <- winter_standard_dev_all_589 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_589 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 4.133977
1988 4.495779
1989 5.141626
1990 4.440235
1991 4.189530
1992 3.258024
1993 4.205984
1995 4.352466
1996 4.113803
1998 4.012343
1999 4.368014
2000 4.319859
2001 4.226953
2002 4.221560
2003 3.885300
2004 4.824928
2005 4.240759
2007 4.539646
2008 4.291670
2015 3.944934
2016 4.194454
2017 4.444266
2018 4.123420
2019 3.891219
2020 3.896219
2021 3.946403
2022 4.116368
ggplot(winter_standard_dev_all_589, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 589 average winter temperatures for water years 2005-2021

winter MK & SS for 589 (non-corrected)

winter_sd_mk_589 <- mk.test(winter_standard_dev_all_589$sd_2)
print(winter_sd_mk_589)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_589$sd_2
## z = -1.5844, n = 27, p-value = 0.1131
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -77.0000000 2301.0000000   -0.2193732
winter_sd_sens_589 <- sens.slope(winter_standard_dev_all_589$sd_2)
print(winter_sd_sens_589)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_589$sd_2
## z = -1.5844, n = 27, p-value = 0.1131
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.023697940  0.003023838
## sample estimates:
## Sen's slope 
##  -0.0124262

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_589_ad <- standard_dev_589_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_589_ad <- summer_standard_dev_all_589_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_589_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 1.593394
1988 2.069605
1989 2.649666
1990 2.190634
1991 1.871522
1992 1.998161
1993 2.127312
1995 2.597275
1996 1.635962
1998 1.992864
1999 2.059130
2000 1.639486
2001 2.142713
2002 2.115650
2003 1.935219
2004 2.030110
2005 2.125556
2007 1.764783
2008 1.772552
2015 2.082037
2016 2.220474
2017 1.757774
2018 1.488552
2019 1.893906
2020 2.163736
2021 2.296548
2022 2.072301
ggplot(summer_standard_dev_all_589_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 589 average summer temperatures for water years 1986-2021

summer MK & SS 589 (corrected)

summer_sd_mk_589_ad <- mk.test(summer_standard_dev_all_589_ad$sd_2)
print(summer_sd_mk_589_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_589_ad$sd_2
## z = -0.041694, n = 27, p-value = 0.9667
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
## -3.000000e+00  2.301000e+03 -8.547009e-03
summer_sd_sens_589_ad <- sens.slope(summer_standard_dev_all_589_ad$sd_2)
print(summer_sd_sens_589_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_589_ad$sd_2
## z = -0.041694, n = 27, p-value = 0.9667
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01702545  0.01182876
## sample estimates:
##  Sen's slope 
## -0.001163945

Winter

winter_standard_dev_all_589_ad <- standard_dev_589_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_589_ad <- winter_standard_dev_all_589_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_589_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 4.005104
1988 4.363022
1989 5.001456
1990 4.315989
1991 4.099130
1992 3.149888
1993 4.085841
1995 4.200787
1996 3.967652
1998 3.879403
1999 4.205619
2000 4.157859
2001 4.114437
2002 4.066752
2003 3.771748
2004 4.667022
2005 4.113866
2007 4.548908
2008 4.308627
2015 3.944050
2016 4.185914
2017 4.448461
2018 4.112202
2019 3.876609
2020 3.894214
2021 3.937900
2022 4.113661
ggplot(winter_standard_dev_all_589_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 589 average winter temperatures for water years 1986-2021

winter MK & SS 589 (corrected)

winter_sd_mk_589_ad <- mk.test(winter_standard_dev_all_589_ad$sd_2)
print(winter_sd_mk_589_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_589_ad$sd_2
## z = -0.91726, n = 27, p-value = 0.359
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -45.0000000 2301.0000000   -0.1282051
winter_sd_sens_589_ad <- sens.slope(winter_standard_dev_all_589_ad$sd_2)
print(winter_sd_sens_589_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_589_ad$sd_2
## z = -0.91726, n = 27, p-value = 0.359
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.020084497  0.008389839
## sample estimates:
##  Sen's slope 
## -0.004681432

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_589 <- standard_dev_589 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_589 <- spring_standard_dev_all_589 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_589 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.830151
1988 3.879924
1989 3.848893
1990 2.904029
1991 3.775776
1992 2.667019
1993 2.829827
1995 2.974210
1996 3.889015
1998 3.349691
1999 3.575717
2000 3.514903
2001 3.136105
2002 2.708591
2003 3.588411
2004 2.964354
2005 3.331322
2007 2.965871
2008 3.200128
2015 3.046492
2016 2.963366
2017 3.801026
2018 2.827887
2019 3.357220
2020 2.712882
2021 2.646430
2022 3.465143
ggplot(spring_standard_dev_all_589, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 589 average spring temperatures for water years 2005-2021

spring MK & SS for 589 (non-corrected)

spring_sd_mk_589 <- mk.test(spring_standard_dev_all_589$sd_2)
print(spring_sd_mk_589)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_589$sd_2
## z = -1.1674, n = 27, p-value = 0.243
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -57.0000000 2301.0000000   -0.1623932
spring_sd_sens_589 <- sens.slope(spring_standard_dev_all_589$sd_2)
print(spring_sd_sens_589)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_589$sd_2
## z = -1.1674, n = 27, p-value = 0.243
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.040547818  0.009462788
## sample estimates:
## Sen's slope 
## -0.01411967

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_589 <- standard_dev_589 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_589 <- fall_standard_dev_all_589 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_589 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.940584
1988 2.479812
1989 2.185278
1990 3.462654
1991 2.681234
1992 3.292748
1993 2.554190
1995 2.830913
1996 3.437792
1998 3.355404
1999 2.815237
2000 2.789609
2001 2.414796
2002 2.678138
2003 2.490480
2004 3.358028
2005 2.555652
2007 2.742051
2008 3.130649
2015 2.231869
2016 2.280083
2017 3.422206
2018 2.634672
2019 2.792804
2020 4.203891
2021 3.027586
2022 2.943353
ggplot(fall_standard_dev_all_589, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 589 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 589 (non-corrected)

fall_sd_mk_589 <- mk.test(fall_standard_dev_all_589$sd_2)
print(fall_sd_mk_589)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_589$sd_2
## z = 0.37524, n = 27, p-value = 0.7075
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 1.900000e+01 2.301000e+03 5.413105e-02
fall_sd_sens_589 <- sens.slope(fall_standard_dev_all_589$sd_2)
print(fall_sd_sens_589)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_589$sd_2
## z = 0.37524, n = 27, p-value = 0.7075
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02018817  0.03097971
## sample estimates:
## Sen's slope 
## 0.005056011

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_589_ad <- standard_dev_589_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_589_ad <- spring_standard_dev_all_589_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_589_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.622433
1988 3.591326
1989 3.548248
1990 2.688703
1991 3.502009
1992 2.468832
1993 2.607578
1995 2.767837
1996 3.563634
1998 3.076367
1999 3.315671
2000 3.211738
2001 2.871104
2002 2.468914
2003 3.299994
2004 2.727279
2005 3.055007
2007 2.952075
2008 3.215989
2015 2.978722
2016 2.939711
2017 3.762371
2018 2.839366
2019 3.282494
2020 2.744598
2021 2.634829
2022 3.475973
ggplot(spring_standard_dev_all_589_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 589 average spring temperatures for water years 1986-2021

spring MK & SS 589 (corrected)

spring_sd_mk_589_ad <- mk.test(spring_standard_dev_all_589_ad$sd_2)
print(spring_sd_mk_589_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_589_ad$sd_2
## z = -0.041694, n = 27, p-value = 0.9667
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
## -3.000000e+00  2.301000e+03 -8.547009e-03
spring_sd_sens_589_ad <- sens.slope(spring_standard_dev_all_589_ad$sd_2)
print(spring_sd_sens_589_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_589_ad$sd_2
## z = -0.041694, n = 27, p-value = 0.9667
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03022519  0.02026685
## sample estimates:
##  Sen's slope 
## -0.001367024

Fall

fall_standard_dev_all_589_ad <- standard_dev_589_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_589_ad <- fall_standard_dev_all_589_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_589_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.764126
1988 2.289772
1989 2.022950
1990 3.161188
1991 2.486066
1992 3.059151
1993 2.370357
1995 2.549990
1996 3.189887
1998 3.066659
1999 2.611954
2000 2.547903
2001 2.185026
2002 2.478066
2003 2.278587
2004 3.108190
2005 2.279954
2007 2.807974
2008 3.106933
2015 2.173088
2016 2.232258
2017 3.363609
2018 2.607143
2019 2.851978
2020 4.262057
2021 3.038272
2022 3.003913
ggplot(fall_standard_dev_all_589_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 589 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 589 (corrected)

fall_sd_mk_589_ad <- mk.test(fall_standard_dev_all_589_ad$sd_2)
print(fall_sd_mk_589_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_589_ad$sd_2
## z = 1.0007, n = 27, p-value = 0.317
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   49.0000000 2301.0000000    0.1396011
fall_sd_sens_589_ad <- sens.slope(fall_standard_dev_all_589_ad$sd_2)
print(fall_sd_sens_589_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_589_ad$sd_2
## z = 1.0007, n = 27, p-value = 0.317
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.009479754  0.040873445
## sample estimates:
## Sen's slope 
##  0.01538702

Middle Creek 624

Morrisey 6/26/2006

snotel_624 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "624")
#str(snotel_624) # check the date, usually a character.  

snotel_624$Date <- as.Date(snotel_624$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_624_clean <- snotel_624 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_624_clean <- snotel_624_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_624_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_624_clean <- snotel_624_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_624_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
snotel_624_cull_count <- snotel_624_clean %>% 
  filter(temperature_min > -40) %>% 
  count(waterYear)

snotel_624_cull_count
## # A tibble: 43 x 2
## # Groups:   waterYear [43]
##    waterYear     n
##        <dbl> <int>
##  1      1980    59
##  2      1981   354
##  3      1982     1
##  4      1983   312
##  5      1984   360
##  6      1985   362
##  7      1986   364
##  8      1987   360
##  9      1988   340
## 10      1989   363
## # ... with 33 more rows
# filtering for too few observations in a year
snotel_624_cull_count_days <- snotel_624_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_624_cull_count_days
## # A tibble: 9 x 2
## # Groups:   waterYear [9]
##   waterYear     n
##       <dbl> <int>
## 1      1980    59
## 2      1982     1
## 3      1983   312
## 4      1988   340
## 5      1991   338
## 6      1993   330
## 7      1994   330
## 8      2021   338
## 9      2022   348

1980, 1982, 1983, 1988, 1991, 1993, 1994, 2021, 2022 need to be culled.

snotel_624_clean_culled <- snotel_624_clean %>% 
  filter(waterYear != "1980" & waterYear != "1981" & waterYear != "1982" & waterYear != "1983" & waterYear != "1988" & waterYear != "1991" & waterYear != "1993" & waterYear != "1994" & waterYear != "2021" & waterYear != "2022")# & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_624_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_624_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_624_xts <- xts(snotel_624_clean_culled$temperature_mean, order.by = snotel_624_clean_culled$Date)

dygraph(temp_624_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
snotel_624_clean_culled <- snotel_624_clean_culled %>% 
  filter(temperature_mean < 20)

temp_624_xts <- xts(snotel_624_clean_culled$temperature_mean, order.by = snotel_624_clean_culled$Date)

dygraph(temp_624_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Middle Creek 624 Morrisey 6/26/2006

snotel_624_adjusted <- snotel_624_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2006-06-26", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

624 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_624 <- snotel_624_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_624 <- yearly_wy_aver_624 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(temperature_mean))

#average mean temperature by day for the period of record:

daily_wy_aver_624 <- daily_wy_aver_624 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_624$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_624 <-daily_wy_aver_624 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_624$date_temp <- signif(daily_wy_aver2_624$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_624, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

624 SD

standard_dev_624 <- daily_wy_aver_624 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_624 <- standard_dev_624 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_624 <- standard_dev_all_624 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_624 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 3.470773
1985 3.635491
1986 3.484612
1987 3.279361
1989 3.906820
1990 3.695695
1992 3.754406
1995 3.545364
1996 3.668774
1997 3.605081
1998 3.496979
1999 3.546766
2000 3.531628
2001 3.480624
2002 3.309932
2003 3.305365
2004 3.638996
2005 3.309117
2006 3.458272
2007 3.397634
2008 3.508620
2009 3.429191
2010 3.438057
2011 3.631695
2012 3.271605
2013 3.756956
2014 3.324254
2015 3.479017
2016 3.499445
2017 3.660121
2018 3.261211
2019 3.331911
2020 3.371898
ggplot(standard_dev_all_624, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 624 average temperatures for water years 2005-2021

MK & SS for 624 (non-corrected)

sd_mk_624 <- mk.test(standard_dev_all_624$sd_2)
print(sd_mk_624)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_624$sd_2
## z = -2.0608, n = 33, p-value = 0.03933
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -134.0000000 4165.3333333   -0.2537879
sd_sens_624 <- sens.slope(standard_dev_all_624$sd_2)
print(sd_sens_624)
## 
##  Sen's slope
## 
## data:  standard_dev_all_624$sd_2
## z = -2.0608, n = 33, p-value = 0.03933
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.012369867 -0.000271526
## sample estimates:
##  Sen's slope 
## -0.006522564

Corrected

624 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_624_ad <- snotel_624_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_624_ad <- yearly_wy_aver_624_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_624_ad <- daily_wy_aver_624_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_624_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_624_ad <-daily_wy_aver_624_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_624_ad$date_temp_ad <- signif(daily_wy_aver2_624_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_624_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

624 SS (corrected)

standard_dev_624_ad <- daily_wy_aver_624_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_624_ad <- standard_dev_624_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_624_ad <- standard_dev_all_624_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_624_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 3.311066
1985 3.483899
1986 3.360675
1987 3.125418
1989 3.717913
1990 3.515274
1992 3.622861
1995 3.383936
1996 3.501911
1997 3.459388
1998 3.302878
1999 3.423315
2000 3.370284
2001 3.301960
2002 3.107878
2003 3.120443
2004 3.480520
2005 3.143260
2006 3.396534
2007 3.396475
2008 3.528459
2009 3.390817
2010 3.493972
2011 3.649500
2012 3.289103
2013 3.788638
2014 3.310799
2015 3.405904
2016 3.487494
2017 3.602564
2018 3.216291
2019 3.344568
2020 3.383103
ggplot(standard_dev_all_624_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 624 average temperatures for water years 1986-2021

MK & SS 624 (corrected)

sd_mk_624_ad <- mk.test(standard_dev_all_624_ad$sd_2)
print(sd_mk_624_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_624_ad$sd_2
## z = -0.015494, n = 33, p-value = 0.9876
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
## -2.000000e+00  4.165333e+03 -3.787879e-03
sd_sens_624_ad <- sens.slope(standard_dev_all_624_ad$sd_2)
print(sd_sens_624_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_624_ad$sd_2
## z = -0.015494, n = 33, p-value = 0.9876
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.005219098  0.006960077
## sample estimates:
##   Sen's slope 
## -2.179565e-05

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_624 <- standard_dev_624 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_624 <- summer_standard_dev_all_624 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_624 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 1.704905
1985 1.847837
1986 1.885452
1987 1.781897
1989 2.465683
1990 2.954581
1992 2.332741
1995 2.836210
1996 1.695902
1997 1.808165
1998 2.179289
1999 1.865343
2000 1.712658
2001 1.991811
2002 1.928808
2003 2.126672
2004 2.212300
2005 2.183621
2006 1.983046
2007 1.754476
2008 1.800370
2009 1.864073
2010 2.132455
2011 1.550850
2012 1.738642
2013 1.876902
2014 1.611348
2015 1.995338
2016 2.191281
2017 1.801049
2018 1.692572
2019 2.112423
2020 2.032966
ggplot(summer_standard_dev_all_624, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 624 average summer temperatures for water years 2005-2021

summer MK & SS for 624 (non-corrected)

summer_sd_mk_624 <- mk.test(summer_standard_dev_all_624$sd_2)
print(summer_sd_mk_624)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_624$sd_2
## z = -0.72824, n = 33, p-value = 0.4665
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -48.00000000 4165.33333333   -0.09090909
summer_sd_sens_624 <- sens.slope(summer_standard_dev_all_624$sd_2)
print(summer_sd_sens_624)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_624$sd_2
## z = -0.72824, n = 33, p-value = 0.4665
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.015933437  0.005673132
## sample estimates:
##  Sen's slope 
## -0.003750575

Winter

winter_standard_dev_all_624 <- standard_dev_624 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_624 <- winter_standard_dev_all_624 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_624 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 4.195347
1985 4.344350
1986 4.386418
1987 4.133825
1989 4.798856
1990 4.562686
1992 4.278105
1995 4.123406
1996 4.388072
1997 4.521833
1998 4.001638
1999 4.170506
2000 4.446390
2001 4.163706
2002 3.998689
2003 3.853912
2004 4.461320
2005 4.038040
2006 4.414162
2007 4.391837
2008 4.452950
2009 4.153846
2010 3.791593
2011 4.623797
2012 4.075673
2013 4.942938
2014 3.708920
2015 4.141000
2016 4.508240
2017 4.253447
2018 4.070115
2019 3.929031
2020 3.729890
ggplot(winter_standard_dev_all_624, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 624 average winter temperatures for water years 2005-2021

winter MK & SS for 624 (non-corrected)

winter_sd_mk_624 <- mk.test(winter_standard_dev_all_624$sd_2)
print(winter_sd_mk_624)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_624$sd_2
## z = -1.5649, n = 33, p-value = 0.1176
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -102.0000000 4165.3333333   -0.1931818
winter_sd_sens_624 <- sens.slope(winter_standard_dev_all_624$sd_2)
print(winter_sd_sens_624)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_624$sd_2
## z = -1.5649, n = 33, p-value = 0.1176
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.020543354  0.002638167
## sample estimates:
##  Sen's slope 
## -0.009214363

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_624_ad <- standard_dev_624_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_624_ad <- summer_standard_dev_all_624_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_624_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 1.535957
1985 1.674125
1986 1.702088
1987 1.601188
1989 2.206416
1990 2.661556
1992 2.123913
1995 2.563834
1996 1.528055
1997 1.633720
1998 1.958088
1999 1.681892
2000 1.555745
2001 1.797420
2002 1.741701
2003 1.899808
2004 2.006451
2005 1.944344
2006 1.951096
2007 1.760908
2008 1.793039
2009 1.896264
2010 2.107742
2011 1.546601
2012 1.698975
2013 1.844642
2014 1.592512
2015 1.979872
2016 2.183047
2017 1.779007
2018 1.669349
2019 2.117031
2020 2.034744
ggplot(summer_standard_dev_all_624_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 624 average summer temperatures for water years 1986-2021

summer MK & SS 624 (corrected)

summer_sd_mk_624_ad <- mk.test(summer_standard_dev_all_624_ad$sd_2)
print(summer_sd_mk_624_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_624_ad$sd_2
## z = 0.91417, n = 33, p-value = 0.3606
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   60.0000000 4165.3333333    0.1136364
summer_sd_sens_624_ad <- sens.slope(summer_standard_dev_all_624_ad$sd_2)
print(summer_sd_sens_624_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_624_ad$sd_2
## z = 0.91417, n = 33, p-value = 0.3606
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.005958612  0.013934786
## sample estimates:
## Sen's slope 
## 0.004937039

Winter

winter_standard_dev_all_624_ad <- standard_dev_624_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_624_ad <- winter_standard_dev_all_624_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_624_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 4.107683
1985 4.275558
1986 4.261888
1987 4.026284
1989 4.669520
1990 4.452435
1992 4.146899
1995 4.014042
1996 4.267020
1997 4.406585
1998 3.905640
1999 4.049789
2000 4.312645
2001 4.083845
2002 3.879027
2003 3.753761
2004 4.342876
2005 3.940788
2006 4.300141
2007 4.395416
2008 4.468621
2009 4.146082
2010 3.798094
2011 4.621621
2012 4.074210
2013 4.945136
2014 3.704931
2015 4.139263
2016 4.501305
2017 4.254747
2018 4.063646
2019 3.921159
2020 3.729670
ggplot(winter_standard_dev_all_624_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 624 average winter temperatures for water years 1986-2021

winter MK & SS 624 (corrected)

winter_sd_mk_624_ad <- mk.test(winter_standard_dev_all_624_ad$sd_2)
print(winter_sd_mk_624_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_624_ad$sd_2
## z = -0.85219, n = 33, p-value = 0.3941
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -56.0000000 4165.3333333   -0.1060606
winter_sd_sens_624_ad <- sens.slope(winter_standard_dev_all_624_ad$sd_2)
print(winter_sd_sens_624_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_624_ad$sd_2
## z = -0.85219, n = 33, p-value = 0.3941
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01618567  0.00665546
## sample estimates:
##  Sen's slope 
## -0.005073559

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_624 <- standard_dev_624 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_624 <- spring_standard_dev_all_624 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_624 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 4.335960
1985 2.827510
1986 3.168663
1987 2.911835
1989 3.860545
1990 2.395987
1992 2.761449
1995 3.263286
1996 3.899850
1997 3.298018
1998 3.425858
1999 3.594708
2000 3.569256
2001 3.487726
2002 2.639586
2003 3.526185
2004 3.043601
2005 3.382032
2006 2.761651
2007 3.187630
2008 3.362782
2009 3.459797
2010 3.731440
2011 3.803986
2012 3.203479
2013 3.397489
2014 4.026664
2015 2.952591
2016 2.965081
2017 3.978277
2018 3.146588
2019 3.613347
2020 2.965346
ggplot(spring_standard_dev_all_624, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 624 average spring temperatures for water years 2005-2021

spring MK & SS for 624 (non-corrected)

spring_sd_mk_624 <- mk.test(spring_standard_dev_all_624$sd_2)
print(spring_sd_mk_624)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_624$sd_2
## z = 0.60428, n = 33, p-value = 0.5457
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 4.000000e+01 4.165333e+03 7.575758e-02
spring_sd_sens_624 <- sens.slope(spring_standard_dev_all_624$sd_2)
print(spring_sd_sens_624)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_624$sd_2
## z = 0.60428, n = 33, p-value = 0.5457
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01435696  0.02530019
## sample estimates:
## Sen's slope 
## 0.006052263

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_624 <- standard_dev_624 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_624 <- fall_standard_dev_all_624 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_624 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 2.087442
1985 3.356906
1986 2.722488
1987 2.558690
1989 2.397686
1990 3.136239
1992 3.640867
1995 2.816530
1996 3.466427
1997 3.384810
1998 3.544662
1999 2.918633
2000 2.707465
2001 2.360696
2002 2.604491
2003 2.806274
2004 3.482719
2005 2.514097
2006 2.578340
2007 2.493800
2008 2.807482
2009 2.909310
2010 3.709644
2011 2.563801
2012 2.578974
2013 2.486587
2014 3.198952
2015 2.386292
2016 2.163861
2017 3.148761
2018 2.625672
2019 2.762273
2020 4.211584
ggplot(fall_standard_dev_all_624, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 624 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 624 (non-corrected)

fall_sd_mk_624 <- mk.test(fall_standard_dev_all_624$sd_2)
print(fall_sd_mk_624)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_624$sd_2
## z = -0.32538, n = 33, p-value = 0.7449
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -22.00000000 4165.33333333   -0.04166667
fall_sd_sens_624 <- sens.slope(fall_standard_dev_all_624$sd_2)
print(fall_sd_sens_624)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_624$sd_2
## z = -0.32538, n = 33, p-value = 0.7449
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02181297  0.01596577
## sample estimates:
## Sen's slope 
## -0.00323131

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_624_ad <- standard_dev_624_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_624_ad <- spring_standard_dev_all_624_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_624_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 4.018683
1985 2.641180
1986 2.951019
1987 2.719415
1989 3.583255
1990 2.239123
1992 2.607665
1995 3.067162
1996 3.596341
1997 3.082847
1998 3.180300
1999 3.378082
2000 3.280318
2001 3.238945
2002 2.451083
2003 3.283854
2004 2.823962
2005 3.121316
2006 2.566194
2007 3.157708
2008 3.366001
2009 3.484760
2010 3.745462
2011 3.781383
2012 3.188815
2013 3.408892
2014 4.034124
2015 2.898940
2016 2.951053
2017 3.948440
2018 3.150902
2019 3.550131
2020 2.974788
ggplot(spring_standard_dev_all_624_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 624 average spring temperatures for water years 1986-2021

spring MK & SS 624 (corrected)

spring_sd_mk_624_ad <- mk.test(spring_standard_dev_all_624_ad$sd_2)
print(spring_sd_mk_624_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_624_ad$sd_2
## z = 1.6889, n = 33, p-value = 0.09124
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  110.0000000 4165.3333333    0.2083333
spring_sd_sens_624_ad <- sens.slope(spring_standard_dev_all_624_ad$sd_2)
print(spring_sd_sens_624_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_624_ad$sd_2
## z = 1.6889, n = 33, p-value = 0.09124
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.003455895  0.032701865
## sample estimates:
## Sen's slope 
##  0.01620511

Fall

fall_standard_dev_all_624_ad <- standard_dev_624_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_624_ad <- fall_standard_dev_all_624_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_624_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 1.950203
1985 3.132641
1986 2.555021
1987 2.392331
1989 2.249269
1990 2.854986
1992 3.426637
1995 2.572362
1996 3.251147
1997 3.135409
1998 3.279627
1999 2.722226
2000 2.503802
2001 2.154109
2002 2.437974
2003 2.588206
2004 3.247744
2005 2.293362
2006 2.777010
2007 2.534600
2008 2.761926
2009 2.875100
2010 3.783468
2011 2.548541
2012 2.594872
2013 2.497189
2014 3.264078
2015 2.326408
2016 2.133515
2017 3.081069
2018 2.590466
2019 2.814961
2020 4.252886
ggplot(fall_standard_dev_all_624_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 624 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 624 (corrected)

fall_sd_mk_624_ad <- mk.test(fall_standard_dev_all_624_ad$sd_2)
print(fall_sd_mk_624_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_624_ad$sd_2
## z = 0.69725, n = 33, p-value = 0.4856
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 4.600000e+01 4.165333e+03 8.712121e-02
fall_sd_sens_624_ad <- sens.slope(fall_standard_dev_all_624_ad$sd_2)
print(fall_sd_sens_624_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_624_ad$sd_2
## z = 0.69725, n = 33, p-value = 0.4856
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01282113  0.02336345
## sample estimates:
## Sen's slope 
## 0.004701515

Molas Lake 632

NSCE-Morrisey, Bias-Original 10/2/2003

snotel_632 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "632")
#str(snotel_632) # check the date, usually a character.  

snotel_632$Date <- as.Date(snotel_632$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_632_clean <- snotel_632 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_632_clean <- snotel_632_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_632_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_632_clean <- snotel_632_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  #filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_632_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
snotel_632_cull_count <- snotel_632_clean %>% 
  filter(temperature_min > -40) %>% 
  count(waterYear)

snotel_632_cull_count
## # A tibble: 37 x 2
## # Groups:   waterYear [37]
##    waterYear     n
##        <dbl> <int>
##  1      1986    54
##  2      1987   355
##  3      1988   362
##  4      1989   364
##  5      1990   365
##  6      1991   365
##  7      1992   366
##  8      1993   303
##  9      1994   294
## 10      1995   361
## # ... with 27 more rows
# filtering for too few observations in a year
snotel_632_cull_count_days <- snotel_632_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_632_cull_count_days
## # A tibble: 6 x 2
## # Groups:   waterYear [6]
##   waterYear     n
##       <dbl> <int>
## 1      1986    54
## 2      1993   303
## 3      1994   295
## 4      2005   344
## 5      2006   304
## 6      2013   248

1986, 1993, 1994, 2005, 2006, 2013 need to be culled.

snotel_632_clean_culled <- snotel_632_clean %>% 
  filter(waterYear != "1986" & waterYear != "1993" & waterYear != "1994" & waterYear != "2005" & waterYear != "2006" & waterYear != "2013")# & waterYear != "1993" & waterYear != "1994" & waterYear != "2021" & waterYear != "2022") & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_632_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_632_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_632_xts <- xts(snotel_632_clean_culled$temperature_mean, order.by = snotel_632_clean_culled$Date)

dygraph(temp_632_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
snotel_632_clean_culled <- snotel_632_clean_culled %>% 
  filter(temperature_mean < 20)

temp_632_xts <- xts(snotel_632_clean_culled$temperature_mean, order.by = snotel_632_clean_culled$Date)

dygraph(temp_632_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Molas Lake 632

NSCE-Morrisey, Bias-Original 10/2/2003

snotel_632_adjusted <- snotel_632_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2003-10-02", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

632 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_632 <- snotel_632_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_632 <- yearly_wy_aver_632 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(temperature_mean))

#average mean temperature by day for the period of record:

daily_wy_aver_632 <- daily_wy_aver_632 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_632$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_632 <-daily_wy_aver_632 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_632$date_temp <- signif(daily_wy_aver2_632$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_632, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

632 SD

standard_dev_632 <- daily_wy_aver_632 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_632 <- standard_dev_632 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_632 <- standard_dev_all_632 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_632 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.130517
1988 3.340453
1989 3.750530
1990 3.170713
1991 3.264872
1992 2.885325
1995 3.544799
1996 3.492733
1997 3.401016
1998 3.307187
1999 3.319979
2000 3.277646
2001 3.724594
2002 3.265778
2003 3.211356
2004 3.328791
2007 3.282053
2008 3.172231
2009 3.179254
2010 3.102352
2011 3.509238
2012 3.006935
2014 3.151779
2015 3.135268
2016 3.282453
2017 3.332492
2018 3.016069
2019 3.059858
2020 3.076814
2021 3.075174
2022 3.117570
ggplot(standard_dev_all_632, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 632 average temperatures for water years 2005-2021

MK & SS for 632 (non-corrected)

sd_mk_632 <- mk.test(standard_dev_all_632$sd_2)
print(sd_mk_632)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_632$sd_2
## z = -2.6514, n = 31, p-value = 0.008015
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -157.0000000 3461.6666667   -0.3376344
sd_sens_632 <- sens.slope(standard_dev_all_632$sd_2)
print(sd_sens_632)
## 
##  Sen's slope
## 
## data:  standard_dev_all_632$sd_2
## z = -2.6514, n = 31, p-value = 0.008015
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.017304726 -0.003590629
## sample estimates:
## Sen's slope 
## -0.01031793

Corrected

632 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_632_ad <- snotel_632_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_632_ad <- yearly_wy_aver_632_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_632_ad <- daily_wy_aver_632_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_632_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_632_ad <-daily_wy_aver_632_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_632_ad$date_temp_ad <- signif(daily_wy_aver2_632_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_632_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

632 SS (corrected)

standard_dev_632_ad <- daily_wy_aver_632_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_632_ad <- standard_dev_632_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_632_ad <- standard_dev_all_632_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_632_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.974266
1988 3.168071
1989 3.569384
1990 3.012923
1991 3.126633
1992 2.752973
1995 3.361866
1996 3.303285
1997 3.235926
1998 3.083547
1999 3.207720
2000 3.101973
2001 3.588371
2002 3.034566
2003 3.006926
2004 3.303693
2007 3.295611
2008 3.211079
2009 3.145310
2010 3.154444
2011 3.518254
2012 3.019993
2014 3.142816
2015 3.068123
2016 3.274518
2017 3.292930
2018 2.973933
2019 3.083510
2020 3.110487
2021 3.107226
2022 3.110047
ggplot(standard_dev_all_632_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 632 average temperatures for water years 1986-2021

MK & SS 632 (corrected)

sd_mk_632_ad <- mk.test(standard_dev_all_632_ad$sd_2)
print(sd_mk_632_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_632_ad$sd_2
## z = -0.54389, n = 31, p-value = 0.5865
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -33.00000000 3461.66666667   -0.07096774
sd_sens_632_ad <- sens.slope(standard_dev_all_632_ad$sd_2)
print(sd_sens_632_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_632_ad$sd_2
## z = -0.54389, n = 31, p-value = 0.5865
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.008401658  0.004865055
## sample estimates:
##  Sen's slope 
## -0.001338925

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_632 <- standard_dev_632 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_632 <- summer_standard_dev_all_632 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_632 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 1.862589
1988 1.733027
1989 2.302099
1990 2.421729
1991 1.783653
1992 2.209273
1995 2.790494
1996 1.783326
1997 1.732259
1998 2.248570
1999 1.949488
2000 1.555497
2001 2.621531
2002 2.051627
2003 1.960385
2004 2.062258
2007 1.692297
2008 1.738802
2009 1.810883
2010 1.972480
2011 1.317170
2012 1.566274
2014 1.526808
2015 1.932472
2016 2.100710
2017 1.711086
2018 1.502211
2019 1.869252
2020 1.814873
2021 2.194149
2022 1.953598
ggplot(summer_standard_dev_all_632, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 632 average summer temperatures for water years 2005-2021

summer MK & SS for 632 (non-corrected)

summer_sd_mk_632 <- mk.test(summer_standard_dev_all_632$sd_2)
print(summer_sd_mk_632)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_632$sd_2
## z = -1.3937, n = 31, p-value = 0.1634
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -83.0000000 3461.6666667   -0.1784946
summer_sd_sens_632 <- sens.slope(summer_standard_dev_all_632$sd_2)
print(summer_sd_sens_632)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_632$sd_2
## z = -1.3937, n = 31, p-value = 0.1634
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.023519761  0.003033628
## sample estimates:
## Sen's slope 
## -0.01022702

Winter

winter_standard_dev_all_632 <- standard_dev_632 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_632 <- winter_standard_dev_all_632 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_632 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.874757
1988 4.136905
1989 4.616942
1990 3.905763
1991 4.032367
1992 2.921530
1995 4.162377
1996 4.043729
1997 4.073083
1998 3.748609
1999 3.822180
2000 4.027425
2001 4.172889
2002 3.965028
2003 3.718920
2004 4.055912
2007 4.307841
2008 3.983398
2009 3.892973
2010 3.255788
2011 4.601695
2012 3.739454
2014 3.720294
2015 3.710874
2016 4.241032
2017 4.070877
2018 3.861078
2019 3.658015
2020 3.548141
2021 3.649243
2022 3.757960
ggplot(winter_standard_dev_all_632, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 632 average winter temperatures for water years 2005-2021

winter MK & SS for 632 (non-corrected)

winter_sd_mk_632 <- mk.test(winter_standard_dev_all_632$sd_2)
print(winter_sd_mk_632)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_632$sd_2
## z = -2.0056, n = 31, p-value = 0.0449
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##           S        varS         tau 
## -119.000000 3461.666667   -0.255914
winter_sd_sens_632 <- sens.slope(winter_standard_dev_all_632$sd_2)
print(winter_sd_sens_632)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_632$sd_2
## z = -2.0056, n = 31, p-value = 0.0449
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.0210100915 -0.0005260968
## sample estimates:
## Sen's slope 
## -0.01094802

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_632_ad <- standard_dev_632_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_632_ad <- summer_standard_dev_all_632_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_632_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 1.684635
1988 1.559409
1989 2.055394
1990 2.191301
1991 1.602310
1992 1.990115
1995 2.505647
1996 1.602632
1997 1.561759
1998 2.009616
1999 1.755325
2000 1.412778
2001 2.387497
2002 1.850759
2003 1.739669
2004 2.044220
2007 1.699071
2008 1.741819
2009 1.843643
2010 1.961095
2011 1.315641
2012 1.539797
2014 1.527269
2015 1.924095
2016 2.088204
2017 1.694056
2018 1.477940
2019 1.880741
2020 1.817096
2021 2.164209
2022 1.928012
ggplot(summer_standard_dev_all_632_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 632 average summer temperatures for water years 1986-2021

summer MK & SS 632 (corrected)

summer_sd_mk_632_ad <- mk.test(summer_standard_dev_all_632_ad$sd_2)
print(summer_sd_mk_632_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_632_ad$sd_2
## z = -0.10198, n = 31, p-value = 0.9188
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##   -7.00000000 3461.66666667   -0.01505376
summer_sd_sens_632_ad <- sens.slope(summer_standard_dev_all_632_ad$sd_2)
print(summer_sd_sens_632_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_632_ad$sd_2
## z = -0.10198, n = 31, p-value = 0.9188
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01313461  0.01210569
## sample estimates:
##  Sen's slope 
## -0.001041996

Winter

winter_standard_dev_all_632_ad <- standard_dev_632_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_632_ad <- winter_standard_dev_all_632_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_632_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.760385
1988 4.039324
1989 4.490874
1990 3.784412
1991 3.965623
1992 2.824526
1995 4.018376
1996 3.886043
1997 3.928233
1998 3.620334
1999 3.687900
2000 3.867665
2001 4.057036
2002 3.815710
2003 3.599010
2004 4.061537
2007 4.312885
2008 4.000126
2009 3.887228
2010 3.261547
2011 4.596556
2012 3.734678
2014 3.711143
2015 3.709522
2016 4.234368
2017 4.078557
2018 3.855358
2019 3.652962
2020 3.550833
2021 3.646561
2022 3.757879
ggplot(winter_standard_dev_all_632_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 632 average winter temperatures for water years 1986-2021

winter MK & SS 632 (corrected)

winter_sd_mk_632_ad <- mk.test(winter_standard_dev_all_632_ad$sd_2)
print(winter_sd_mk_632_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_632_ad$sd_2
## z = -1.0198, n = 31, p-value = 0.3078
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -61.0000000 3461.6666667   -0.1311828
winter_sd_sens_632_ad <- sens.slope(winter_standard_dev_all_632_ad$sd_2)
print(winter_sd_sens_632_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_632_ad$sd_2
## z = -1.0198, n = 31, p-value = 0.3078
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.014888856  0.005871266
## sample estimates:
##  Sen's slope 
## -0.005572378

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_632 <- standard_dev_632 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_632 <- spring_standard_dev_all_632 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_632 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.004263
1988 3.295193
1989 3.736881
1990 2.330029
1991 3.380456
1992 2.629853
1995 3.065512
1996 3.716930
1997 3.619774
1998 3.173214
1999 3.393662
2000 3.532666
2001 3.121513
2002 2.632726
2003 3.562033
2004 2.484620
2007 2.900072
2008 2.908697
2009 3.010996
2010 3.652731
2011 3.460518
2012 2.838558
2014 3.481958
2015 2.738310
2016 2.783328
2017 3.447709
2018 2.701257
2019 3.255571
2020 2.426008
2021 2.542010
2022 3.098527
ggplot(spring_standard_dev_all_632, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 632 average spring temperatures for water years 2005-2021

spring MK & SS for 632 (non-corrected)

spring_sd_mk_632 <- mk.test(spring_standard_dev_all_632$sd_2)
print(spring_sd_mk_632)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_632$sd_2
## z = -1.4277, n = 31, p-value = 0.1534
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -85.0000000 3461.6666667   -0.1827957
spring_sd_sens_632 <- sens.slope(spring_standard_dev_all_632$sd_2)
print(spring_sd_sens_632)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_632$sd_2
## z = -1.4277, n = 31, p-value = 0.1534
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.030018257  0.006025385
## sample estimates:
## Sen's slope 
##  -0.0149567

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_632 <- standard_dev_632 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_632 <- fall_standard_dev_all_632 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_632 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.161603
1988 2.408758
1989 2.189754
1990 2.843540
1991 2.607254
1992 2.995109
1995 2.817267
1996 3.432982
1997 3.285145
1998 3.398810
1999 2.708248
2000 2.644728
2001 2.347794
2002 2.531275
2003 2.595986
2004 3.388496
2007 2.382493
2008 2.652647
2009 2.661650
2010 3.365741
2011 2.356449
2012 2.520653
2014 2.950048
2015 2.005093
2016 2.185790
2017 2.921013
2018 2.320244
2019 2.487245
2020 3.619027
2021 2.745717
2022 2.803850
ggplot(fall_standard_dev_all_632, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 632 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 632 (non-corrected)

fall_sd_mk_632 <- mk.test(fall_standard_dev_all_632$sd_2)
print(fall_sd_mk_632)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_632$sd_2
## z = 0, n = 31, p-value = 1
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
## -1.000000e+00  3.461667e+03 -2.150538e-03
fall_sd_sens_632 <- sens.slope(fall_standard_dev_all_632$sd_2)
print(fall_sd_sens_632)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_632$sd_2
## z = 0, n = 31, p-value = 1
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01873011  0.01709762
## sample estimates:
##   Sen's slope 
## -0.0001801696

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_632_ad <- standard_dev_632_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_632_ad <- spring_standard_dev_all_632_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_632_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.812961
1988 3.061013
1989 3.463521
1990 2.187715
1991 3.144347
1992 2.464083
1995 2.861875
1996 3.410019
1997 3.362318
1998 2.913253
1999 3.162991
2000 3.234440
2001 2.950823
2002 2.429939
2003 3.280598
2004 2.474927
2007 2.889505
2008 2.922652
2009 3.044883
2010 3.669644
2011 3.440592
2012 2.829573
2014 3.488839
2015 2.695637
2016 2.769095
2017 3.419820
2018 2.701684
2019 3.204270
2020 2.450516
2021 2.528001
2022 3.106423
ggplot(spring_standard_dev_all_632_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 632 average spring temperatures for water years 1986-2021

spring MK & SS 632 (corrected)

spring_sd_mk_632_ad <- mk.test(spring_standard_dev_all_632_ad$sd_2)
print(spring_sd_mk_632_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_632_ad$sd_2
## z = -0.20396, n = 31, p-value = 0.8384
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -13.00000000 3461.66666667   -0.02795699
spring_sd_sens_632_ad <- sens.slope(spring_standard_dev_all_632_ad$sd_2)
print(spring_sd_sens_632_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_632_ad$sd_2
## z = -0.20396, n = 31, p-value = 0.8384
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02015921  0.01538577
## sample estimates:
##  Sen's slope 
## -0.001885617

Fall

fall_standard_dev_all_632_ad <- standard_dev_632_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_632_ad <- fall_standard_dev_all_632_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_632_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.018507
1988 2.256775
1989 2.055594
1990 2.583606
1991 2.442102
1992 2.796355
1995 2.563575
1996 3.210775
1997 3.002055
1998 3.110780
1999 2.515431
2000 2.445210
2001 2.115526
2002 2.359882
2003 2.368218
2004 3.313066
2007 2.421955
2008 2.621090
2009 2.621854
2010 3.419372
2011 2.356855
2012 2.534319
2014 2.989246
2015 1.947877
2016 2.151126
2017 2.861246
2018 2.282796
2019 2.523767
2020 3.661005
2021 2.737017
2022 2.836946
ggplot(fall_standard_dev_all_632_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 632 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 632 (corrected)

fall_sd_mk_632_ad <- mk.test(fall_standard_dev_all_632_ad$sd_2)
print(fall_sd_mk_632_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_632_ad$sd_2
## z = 1.1897, n = 31, p-value = 0.2341
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   71.0000000 3461.6666667    0.1526882
fall_sd_sens_632_ad <- sens.slope(fall_standard_dev_all_632_ad$sd_2)
print(fall_sd_sens_632_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_632_ad$sd_2
## z = 1.1897, n = 31, p-value = 0.2341
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.008282885  0.026764532
## sample estimates:
## Sen's slope 
##  0.01139044

Red Mountain Pass 713

Morrisey 8/18/2004

snotel_713 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "713")
#str(snotel_713) # check the date, usually a character.  

snotel_713$Date <- as.Date(snotel_713$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_713_clean <- snotel_713 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_713_clean <- snotel_713_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_713_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_713_clean <- snotel_713_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_713_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
snotel_713_cull_count <- snotel_713_clean %>% 
  filter(temperature_min > -40) %>% 
  count(waterYear)

snotel_713_cull_count
## # A tibble: 42 x 2
## # Groups:   waterYear [42]
##    waterYear     n
##        <dbl> <int>
##  1      1981   189
##  2      1982   287
##  3      1983   319
##  4      1984   360
##  5      1985   362
##  6      1986   364
##  7      1987   263
##  8      1988   282
##  9      1989   228
## 10      1990   365
## # ... with 32 more rows
# filtering for too few observations in a year
snotel_713_cull_count_days <- snotel_713_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_713_cull_count_days
## # A tibble: 6 x 2
## # Groups:   waterYear [6]
##   waterYear     n
##       <dbl> <int>
## 1      1981   189
## 2      1982   287
## 3      1983   319
## 4      1987   315
## 5      1989   263
## 6      1994   308

1981, 1982, 1983, 1987, 1989, 1994 need to be culled. 1984 & 1985 are too low.

snotel_713_clean_culled <- snotel_713_clean %>% 
  filter(waterYear > "1985" & waterYear != "1987" & waterYear != "1989" & waterYear != "1994")# & waterYear != "1993" & waterYear != "1994" & waterYear != "2021" & waterYear != "2022") & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_713_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_713_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_713_xts <- xts(snotel_713_clean_culled$temperature_mean, order.by = snotel_713_clean_culled$Date)

dygraph(temp_713_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
snotel_713_clean_culled <- snotel_713_clean_culled %>% 
  filter(temperature_mean < 19.3)

temp_713_xts <- xts(snotel_713_clean_culled$temperature_mean, order.by = snotel_713_clean_culled$Date)

dygraph(temp_713_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Red Mountain Pass 713

Morrisey 8/18/2004

snotel_713_adjusted <- snotel_713_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2004-08-18", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

713 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_713 <- snotel_713_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_713 <- yearly_wy_aver_713 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(temperature_mean))

#average mean temperature by day for the period of record:

daily_wy_aver_713 <- daily_wy_aver_713 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_713$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_713 <-daily_wy_aver_713 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_713$date_temp <- signif(daily_wy_aver2_713$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_713, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

713 SD

standard_dev_713 <- daily_wy_aver_713 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_713 <- standard_dev_713 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_713 <- standard_dev_all_713 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_713 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 3.748262
1988 5.288463
1990 3.265050
1991 3.340586
1992 3.011393
1993 3.024039
1995 3.431745
1996 3.640445
1997 3.567880
1998 3.282683
1999 3.397928
2000 3.375992
2001 3.410458
2002 3.385087
2003 3.238834
2004 3.588366
2005 3.101595
2006 3.352461
2007 3.363166
2008 3.364871
2009 3.326243
2010 3.178142
2011 3.621487
2012 3.084809
2013 3.656355
2014 3.254014
2015 3.230638
2016 3.223591
2017 3.604607
2018 3.156424
2019 3.131630
2020 3.172715
2021 3.158724
2022 3.232802
ggplot(standard_dev_all_713, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 713 average temperatures for water years 2005-2021

MK & SS for 713 (non-corrected)

sd_mk_713 <- mk.test(standard_dev_all_713$sd_2)
print(sd_mk_713)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_713$sd_2
## z = -2.2237, n = 34, p-value = 0.02617
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -151.0000000 4550.3333333   -0.2691622
sd_sens_713 <- sens.slope(standard_dev_all_713$sd_2)
print(sd_sens_713)
## 
##  Sen's slope
## 
## data:  standard_dev_all_713$sd_2
## z = -2.2237, n = 34, p-value = 0.02617
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.014445833 -0.001390215
## sample estimates:
##  Sen's slope 
## -0.008454229

Corrected

713 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_713_ad <- snotel_713_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_713_ad <- yearly_wy_aver_713_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_713_ad <- daily_wy_aver_713_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_713_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_713_ad <-daily_wy_aver_713_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_713_ad$date_temp_ad <- signif(daily_wy_aver2_713_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_713_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

713 SS (corrected)

standard_dev_713_ad <- daily_wy_aver_713_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_713_ad <- standard_dev_713_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_713_ad <- standard_dev_all_713_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_713_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 3.630882
1988 5.155032
1990 3.109239
1991 3.214689
1992 2.879845
1993 2.872782
1995 3.277296
1996 3.467277
1997 3.408858
1998 3.079653
1999 3.293007
2000 3.209082
2001 3.221004
2002 3.164459
2003 3.046025
2004 3.488900
2005 3.085969
2006 3.333020
2007 3.371998
2008 3.388966
2009 3.286354
2010 3.211688
2011 3.627486
2012 3.094949
2013 3.689664
2014 3.243946
2015 3.170575
2016 3.212604
2017 3.563641
2018 3.122596
2019 3.151431
2020 3.200524
2021 3.182992
2022 3.220213
ggplot(standard_dev_all_713_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 713 average temperatures for water years 1986-2021

MK & SS 713 (corrected)

sd_mk_713_ad <- mk.test(standard_dev_all_713_ad$sd_2)
print(sd_mk_713_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_713_ad$sd_2
## z = -0.23719, n = 34, p-value = 0.8125
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -17.00000000 4550.33333333   -0.03030303
sd_sens_713_ad <- sens.slope(standard_dev_all_713_ad$sd_2)
print(sd_sens_713_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_713_ad$sd_2
## z = -0.23719, n = 34, p-value = 0.8125
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.009382059  0.007636994
## sample estimates:
##   Sen's slope 
## -0.0006804749

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_713 <- standard_dev_713 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_713 <- summer_standard_dev_all_713 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_713 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 1.900173
1988 1.890066
1990 2.246261
1991 1.706903
1992 2.162690
1993 2.256077
1995 2.795436
1996 1.791470
1997 1.726750
1998 2.290023
1999 1.944601
2000 1.673129
2001 2.096142
2002 2.155869
2003 2.034258
2004 2.182623
2005 1.996136
2006 1.907303
2007 1.800212
2008 1.748155
2009 1.837670
2010 2.096586
2011 1.531859
2012 1.606412
2013 1.933368
2014 1.527735
2015 1.947717
2016 2.072760
2017 1.670095
2018 1.538018
2019 2.053593
2020 1.996282
2021 2.234494
2022 2.002102
ggplot(summer_standard_dev_all_713, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 713 average summer temperatures for water years 2005-2021

summer MK & SS for 713 (non-corrected)

summer_sd_mk_713 <- mk.test(summer_standard_dev_all_713$sd_2)
print(summer_sd_mk_713)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_713$sd_2
## z = -1.1267, n = 34, p-value = 0.2599
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -77.0000000 4550.3333333   -0.1372549
summer_sd_sens_713 <- sens.slope(summer_standard_dev_all_713$sd_2)
print(summer_sd_sens_713)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_713$sd_2
## z = -1.1267, n = 34, p-value = 0.2599
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.015011892  0.003553857
## sample estimates:
##  Sen's slope 
## -0.006880997

Winter

winter_standard_dev_all_713 <- standard_dev_713 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_713 <- winter_standard_dev_all_713 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_713 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 4.815021
1988 4.734553
1990 4.048972
1991 4.071796
1992 2.955207
1993 3.533591
1995 4.009904
1996 4.199689
1997 4.395122
1998 3.784576
1999 3.909232
2000 4.072786
2001 4.064898
2002 3.993757
2003 3.793276
2004 4.370677
2005 3.861115
2006 4.222397
2007 4.426696
2008 4.223704
2009 4.001859
2010 3.370211
2011 4.721511
2012 3.821636
2013 4.748340
2014 3.756189
2015 3.823991
2016 4.156884
2017 4.313010
2018 4.014748
2019 3.672707
2020 3.491978
2021 3.651568
2022 3.859175
ggplot(winter_standard_dev_all_713, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 713 average winter temperatures for water years 2005-2021

winter MK & SS for 713 (non-corrected)

winter_sd_mk_713 <- mk.test(winter_standard_dev_all_713$sd_2)
print(winter_sd_mk_713)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_713$sd_2
## z = -1.3046, n = 34, p-value = 0.192
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -89.0000000 4550.3333333   -0.1586453
winter_sd_sens_713 <- sens.slope(winter_standard_dev_all_713$sd_2)
print(winter_sd_sens_713)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_713$sd_2
## z = -1.3046, n = 34, p-value = 0.192
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.021573614  0.004316465
## sample estimates:
##  Sen's slope 
## -0.009709588

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_713_ad <- standard_dev_713_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_713_ad <- summer_standard_dev_all_713_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_713_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 1.723182
1988 1.701615
1990 2.032642
1991 1.542076
1992 1.945448
1993 2.020187
1995 2.521727
1996 1.616121
1997 1.560336
1998 2.049643
1999 1.751909
2000 1.521756
2001 1.901720
2002 1.947309
2003 1.809117
2004 2.059940
2005 2.027038
2006 1.883390
2007 1.811727
2008 1.752739
2009 1.867242
2010 2.085293
2011 1.532710
2012 1.580607
2013 1.910373
2014 1.527261
2015 1.945010
2016 2.065475
2017 1.651907
2018 1.513885
2019 2.059976
2020 2.002060
2021 2.208300
2022 1.972297
ggplot(summer_standard_dev_all_713_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 713 average summer temperatures for water years 1986-2021

summer MK & SS 713 (corrected)

summer_sd_mk_713_ad <- mk.test(summer_standard_dev_all_713_ad$sd_2)
print(summer_sd_mk_713_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_713_ad$sd_2
## z = 0.68192, n = 34, p-value = 0.4953
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 4.700000e+01 4.550333e+03 8.377897e-02
summer_sd_sens_713_ad <- sens.slope(summer_standard_dev_all_713_ad$sd_2)
print(summer_sd_sens_713_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_713_ad$sd_2
## z = 0.68192, n = 34, p-value = 0.4953
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.005466085  0.011318846
## sample estimates:
## Sen's slope 
## 0.002099829

Winter

winter_standard_dev_all_713_ad <- standard_dev_713_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_713_ad <- winter_standard_dev_all_713_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_713_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 4.675207
1988 4.677630
1990 3.932472
1991 3.998742
1992 2.872068
1993 3.451997
1995 3.887144
1996 4.070766
1997 4.264003
1998 3.677127
1999 3.789905
2000 3.928555
2001 3.970404
2002 3.870109
2003 3.683997
2004 4.241124
2005 3.847230
2006 4.218950
2007 4.429923
2008 4.237203
2009 3.995448
2010 3.374408
2011 4.719194
2012 3.820495
2013 4.750073
2014 3.752347
2015 3.823960
2016 4.150654
2017 4.319241
2018 4.009712
2019 3.666479
2020 3.494269
2021 3.647848
2022 3.861162
ggplot(winter_standard_dev_all_713_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 713 average winter temperatures for water years 1986-2021

winter MK & SS 713 (corrected)

winter_sd_mk_713_ad <- mk.test(winter_standard_dev_all_713_ad$sd_2)
print(winter_sd_mk_713_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_713_ad$sd_2
## z = -0.65228, n = 34, p-value = 0.5142
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -45.0000000 4550.3333333   -0.0802139
winter_sd_sens_713_ad <- sens.slope(winter_standard_dev_all_713_ad$sd_2)
print(winter_sd_sens_713_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_713_ad$sd_2
## z = -0.65228, n = 34, p-value = 0.5142
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01652944  0.01156875
## sample estimates:
##  Sen's slope 
## -0.003991471

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_713 <- standard_dev_713 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_713 <- spring_standard_dev_all_713 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_713 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 3.146702
1988 3.498995
1990 2.604361
1991 3.615000
1992 2.849591
1993 2.650485
1995 2.985093
1996 3.998135
1997 3.642277
1998 2.996584
1999 3.430900
2000 3.624368
2001 3.409537
2002 2.714589
2003 3.522437
2004 2.883819
2005 3.076456
2006 2.606802
2007 2.925654
2008 3.164325
2009 3.115512
2010 3.766419
2011 3.709376
2012 2.977148
2013 3.201485
2014 3.737685
2015 2.678508
2016 2.702184
2017 3.741379
2018 2.893080
2019 3.418409
2020 2.576909
2021 2.672197
2022 3.374897
ggplot(spring_standard_dev_all_713, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 713 average spring temperatures for water years 2005-2021

spring MK & SS for 713 (non-corrected)

spring_sd_mk_713 <- mk.test(spring_standard_dev_all_713$sd_2)
print(spring_sd_mk_713)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_713$sd_2
## z = -0.38544, n = 34, p-value = 0.6999
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -27.00000000 4550.33333333   -0.04812834
spring_sd_sens_713 <- sens.slope(spring_standard_dev_all_713$sd_2)
print(spring_sd_sens_713)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_713$sd_2
## z = -0.38544, n = 34, p-value = 0.6999
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01925056  0.01166613
## sample estimates:
##  Sen's slope 
## -0.002829845

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_713 <- standard_dev_713 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_713 <- fall_standard_dev_all_713 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_713 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 2.888045
1988 8.800878
1990 3.001053
1991 2.768470
1992 3.454545
1993 2.697859
1995 2.750842
1996 3.729988
1997 3.460296
1998 3.131760
1999 2.895935
2000 2.972675
2001 2.485969
2002 2.826340
2003 2.697098
2004 3.457632
2005 2.165445
2006 2.948826
2007 2.295129
2008 2.937196
2009 3.054366
2010 3.380165
2011 2.273065
2012 2.637669
2013 2.598930
2014 3.187829
2015 2.360422
2016 2.229703
2017 3.278567
2018 2.631376
2019 2.576713
2020 4.012123
2021 2.905674
2022 2.838748
ggplot(fall_standard_dev_all_713, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 713 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 713 (non-corrected)

fall_sd_mk_713 <- mk.test(fall_standard_dev_all_713$sd_2)
print(fall_sd_mk_713)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_713$sd_2
## z = -1.5417, n = 34, p-value = 0.1231
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -105.0000000 4550.3333333   -0.1871658
fall_sd_sens_713 <- sens.slope(fall_standard_dev_all_713$sd_2)
print(fall_sd_sens_713)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_713$sd_2
## z = -1.5417, n = 34, p-value = 0.1231
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.030979181  0.004731176
## sample estimates:
## Sen's slope 
## -0.01037774

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_713_ad <- standard_dev_713_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_713_ad <- spring_standard_dev_all_713_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_713_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 2.933401
1988 3.259655
1990 2.443934
1991 3.395071
1992 2.673158
1993 2.454624
1995 2.806994
1996 3.704436
1997 3.404825
1998 2.764443
1999 3.212571
2000 3.336034
2001 3.152091
2002 2.526493
2003 3.263393
2004 2.683228
2005 3.092336
2006 2.606822
2007 2.916969
2008 3.171054
2009 3.140537
2010 3.771904
2011 3.691844
2012 2.967119
2013 3.219232
2014 3.737851
2015 2.638183
2016 2.681888
2017 3.710012
2018 2.892402
2019 3.366595
2020 2.593596
2021 2.651540
2022 3.377326
ggplot(spring_standard_dev_all_713_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 713 average spring temperatures for water years 1986-2021

spring MK & SS 713 (corrected)

spring_sd_mk_713_ad <- mk.test(spring_standard_dev_all_713_ad$sd_2)
print(spring_sd_mk_713_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_713_ad$sd_2
## z = 0.53368, n = 34, p-value = 0.5936
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 3.700000e+01 4.550333e+03 6.595365e-02
spring_sd_sens_713_ad <- sens.slope(spring_standard_dev_all_713_ad$sd_2)
print(spring_sd_sens_713_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_713_ad$sd_2
## z = 0.53368, n = 34, p-value = 0.5936
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01197081  0.01992482
## sample estimates:
## Sen's slope 
## 0.003687603

Fall

fall_standard_dev_all_713_ad <- standard_dev_713_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_713_ad <- fall_standard_dev_all_713_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_713_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 2.726508
1988 8.685830
1990 2.741277
1991 2.610817
1992 3.239487
1993 2.548639
1995 2.529511
1996 3.502479
1997 3.190722
1998 2.876684
1999 2.707435
2000 2.772790
2001 2.260814
2002 2.659007
2003 2.473508
2004 3.603743
2005 2.181580
2006 2.884743
2007 2.336225
2008 2.908137
2009 3.013022
2010 3.431577
2011 2.260184
2012 2.638813
2013 2.591443
2014 3.226849
2015 2.302334
2016 2.183223
2017 3.215666
2018 2.595956
2019 2.618418
2020 4.049101
2021 2.884893
2022 2.874356
ggplot(fall_standard_dev_all_713_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 713 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 713 (corrected)

fall_sd_mk_713_ad <- mk.test(fall_standard_dev_all_713_ad$sd_2)
print(fall_sd_mk_713_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_713_ad$sd_2
## z = -0.47438, n = 34, p-value = 0.6352
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -33.00000000 4550.33333333   -0.05882353
fall_sd_sens_713_ad <- sens.slope(fall_standard_dev_all_713_ad$sd_2)
print(fall_sd_sens_713_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_713_ad$sd_2
## z = -0.47438, n = 34, p-value = 0.6352
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02168235  0.01256850
## sample estimates:
##  Sen's slope 
## -0.003940739

Scotch Creek 739

Morrisey 6/15/2004

snotel_739 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "739")
#str(snotel_739) # check the date, usually a character.  

snotel_739$Date <- as.Date(snotel_739$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_739_clean <- snotel_739 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_739_clean <- snotel_739_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_739_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_739_clean <- snotel_739_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_739_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
snotel_739_cull_count <- snotel_739_clean %>% 
  filter(temperature_min > -40) %>% 
  count(waterYear)

snotel_739_cull_count
## # A tibble: 36 x 2
## # Groups:   waterYear [36]
##    waterYear     n
##        <dbl> <int>
##  1      1987   345
##  2      1988   273
##  3      1989   363
##  4      1990   365
##  5      1991   365
##  6      1992   365
##  7      1993   342
##  8      1994   345
##  9      1995   362
## 10      1996   365
## # ... with 26 more rows
# filtering for too few observations in a year
snotel_739_cull_count_days <- snotel_739_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_739_cull_count_days
## # A tibble: 6 x 2
## # Groups:   waterYear [6]
##   waterYear     n
##       <dbl> <int>
## 1      1987   345
## 2      1988   273
## 3      1993   343
## 4      1994   345
## 5      2016   320
## 6      2017   249

1987, 1988, 1993, 1994, 2016, 2017 need to be culled.

snotel_739_clean_culled <- snotel_739_clean %>% 
  filter(waterYear != "1987" & waterYear != "1988" & waterYear != "1993" & waterYear != "1994" & waterYear != "2016" & waterYear != "2017")# & waterYear != "1993" & waterYear != "1994" & waterYear != "2021" & waterYear != "2022") & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_739_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_739_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_739_xts <- xts(snotel_739_clean_culled$temperature_mean, order.by = snotel_739_clean_culled$Date)

dygraph(temp_739_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
snotel_739_clean_culled <- snotel_739_clean_culled %>% 
  filter(temperature_mean < 19.3)

temp_739_xts <- xts(snotel_739_clean_culled$temperature_mean, order.by = snotel_739_clean_culled$Date)

dygraph(temp_739_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Scotch Creek 739

Morrisey 6/15/2004

snotel_739_adjusted <- snotel_739_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2004-06-15", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

739 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_739 <- snotel_739_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_739 <- yearly_wy_aver_739 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(temperature_mean))

#average mean temperature by day for the period of record:

daily_wy_aver_739 <- daily_wy_aver_739 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_739$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_739 <-daily_wy_aver_739 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_739$date_temp <- signif(daily_wy_aver2_739$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_739, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

739 SD

standard_dev_739 <- daily_wy_aver_739 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_739 <- standard_dev_739 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_739 <- standard_dev_all_739 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_739 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 3.478391
1990 3.234749
1991 3.731625
1992 3.750728
1995 3.322968
1996 3.196730
1997 3.141998
1998 3.210353
1999 2.941711
2000 3.070103
2001 3.006503
2002 3.292517
2003 2.909168
2004 3.215566
2005 2.897221
2006 3.066124
2007 3.082568
2008 3.012055
2009 2.876942
2010 2.862427
2011 3.369025
2012 2.564890
2013 3.273094
2014 2.841901
2015 2.867468
2018 2.668808
2019 2.864825
2020 2.851687
2021 2.817249
2022 2.786486
ggplot(standard_dev_all_739, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 739 average temperatures for water years 2005-2021

MK & SS for 739 (non-corrected)

sd_mk_739 <- mk.test(standard_dev_all_739$sd_2)
print(sd_mk_739)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_739$sd_2
## z = -4.6387, n = 30, p-value = 3.507e-06
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##        S     varS      tau 
## -261.000 3141.667   -0.600
sd_sens_739 <- sens.slope(standard_dev_all_739$sd_2)
print(sd_sens_739)
## 
##  Sen's slope
## 
## data:  standard_dev_all_739$sd_2
## z = -4.6387, n = 30, p-value = 3.507e-06
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03031008 -0.01419831
## sample estimates:
## Sen's slope 
##  -0.0214593

Corrected

739 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_739_ad <- snotel_739_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_739_ad <- yearly_wy_aver_739_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_739_ad <- daily_wy_aver_739_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_739_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_739_ad <-daily_wy_aver_739_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_739_ad$date_temp_ad <- signif(daily_wy_aver2_739_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_739_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

739 SS (corrected)

standard_dev_739_ad <- daily_wy_aver_739_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_739_ad <- standard_dev_739_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_739_ad <- standard_dev_all_739_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_739_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 3.361340
1990 3.162755
1991 3.638139
1992 3.661441
1995 3.127806
1996 2.982903
1997 2.938276
1998 2.947391
1999 2.810840
2000 2.876666
2001 2.765055
2002 2.990828
2003 2.676054
2004 3.094883
2005 2.892950
2006 3.055522
2007 3.106874
2008 3.057088
2009 2.837512
2010 2.919085
2011 3.387879
2012 2.596033
2013 3.329140
2014 2.842373
2015 2.806888
2018 2.642817
2019 2.894130
2020 2.887175
2021 2.853125
2022 2.802937
ggplot(standard_dev_all_739_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 739 average temperatures for water years 1986-2021

MK & SS 739 (corrected)

sd_mk_739_ad <- mk.test(standard_dev_all_739_ad$sd_2)
print(sd_mk_739_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_739_ad$sd_2
## z = -2.7475, n = 30, p-value = 0.006005
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -155.0000000 3141.6666667   -0.3563218
sd_sens_739_ad <- sens.slope(standard_dev_all_739_ad$sd_2)
print(sd_sens_739_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_739_ad$sd_2
## z = -2.7475, n = 30, p-value = 0.006005
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.022739436 -0.003988791
## sample estimates:
## Sen's slope 
## -0.01353721

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_739 <- standard_dev_739 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_739 <- summer_standard_dev_all_739 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_739 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 2.145740
1990 1.771174
1991 1.843161
1992 2.039378
1995 2.455399
1996 1.679213
1997 1.584730
1998 2.079286
1999 1.914271
2000 1.906042
2001 2.107016
2002 2.047907
2003 1.802612
2004 2.014590
2005 1.844752
2006 1.829165
2007 1.734155
2008 1.667185
2009 1.658490
2010 1.893854
2011 1.335092
2012 1.524713
2013 1.929630
2014 1.505384
2015 1.883735
2018 1.533785
2019 1.665949
2020 1.691805
2021 1.947251
2022 1.799487
ggplot(summer_standard_dev_all_739, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 739 average summer temperatures for water years 2005-2021

summer MK & SS for 739 (non-corrected)

summer_sd_mk_739 <- mk.test(summer_standard_dev_all_739$sd_2)
print(summer_sd_mk_739)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_739$sd_2
## z = -2.4264, n = 30, p-value = 0.01525
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -137.0000000 3141.6666667   -0.3149425
summer_sd_sens_739 <- sens.slope(summer_standard_dev_all_739$sd_2)
print(summer_sd_sens_739)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_739$sd_2
## z = -2.4264, n = 30, p-value = 0.01525
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.022981499 -0.002467916
## sample estimates:
## Sen's slope 
## -0.01176518

Winter

winter_standard_dev_all_739 <- standard_dev_739 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_739 <- winter_standard_dev_all_739 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_739 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 4.346259
1990 3.510086
1991 3.927731
1992 2.951872
1995 4.082570
1996 3.754278
1997 3.750937
1998 3.691930
1999 3.478542
2000 3.830594
2001 3.528868
2002 3.817226
2003 3.394458
2004 4.117968
2005 3.727110
2006 3.882318
2007 4.031203
2008 3.867433
2009 3.533579
2010 3.066796
2011 4.501667
2012 3.097112
2013 4.170282
2014 3.410581
2015 3.320521
2018 3.432570
2019 3.429741
2020 3.432563
2021 3.530950
2022 3.383331
ggplot(winter_standard_dev_all_739, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 739 average winter temperatures for water years 2005-2021

winter MK & SS for 739 (non-corrected)

winter_sd_mk_739 <- mk.test(winter_standard_dev_all_739$sd_2)
print(winter_sd_mk_739)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_739$sd_2
## z = -1.6414, n = 30, p-value = 0.1007
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -93.0000000 3141.6666667   -0.2137931
winter_sd_sens_739 <- sens.slope(winter_standard_dev_all_739$sd_2)
print(winter_sd_sens_739)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_739$sd_2
## z = -1.6414, n = 30, p-value = 0.1007
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.027475433  0.002620407
## sample estimates:
## Sen's slope 
## -0.01402724

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_739_ad <- standard_dev_739_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_739_ad <- summer_standard_dev_all_739_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_739_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 1.938417
1990 1.612757
1991 1.696123
1992 1.874937
1995 2.198336
1996 1.513409
1997 1.424958
1998 1.843615
1999 1.711059
2000 1.726145
2001 1.896099
2002 1.841214
2003 1.591670
2004 1.953607
2005 1.875205
2006 1.803984
2007 1.732178
2008 1.674659
2009 1.683825
2010 1.885406
2011 1.342484
2012 1.501026
2013 1.913835
2014 1.497140
2015 1.873916
2018 1.510833
2019 1.678910
2020 1.688001
2021 1.925436
2022 1.774926
ggplot(summer_standard_dev_all_739_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 739 average summer temperatures for water years 1986-2021

summer MK & SS 739 (corrected)

summer_sd_mk_739_ad <- mk.test(summer_standard_dev_all_739_ad$sd_2)
print(summer_sd_mk_739_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_739_ad$sd_2
## z = -0.6066, n = 30, p-value = 0.5441
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -35.00000000 3141.66666667   -0.08045977
summer_sd_sens_739_ad <- sens.slope(summer_standard_dev_all_739_ad$sd_2)
print(summer_sd_sens_739_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_739_ad$sd_2
## z = -0.6066, n = 30, p-value = 0.5441
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.011167565  0.004828767
## sample estimates:
##  Sen's slope 
## -0.001878042

Winter

winter_standard_dev_all_739_ad <- standard_dev_739_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_739_ad <- winter_standard_dev_all_739_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_739_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 4.219736
1990 3.381562
1991 3.831179
1992 2.837809
1995 3.925615
1996 3.610641
1997 3.611237
1998 3.559693
1999 3.340174
2000 3.672302
2001 3.409879
2002 3.666804
2003 3.273601
2004 3.959016
2005 3.710100
2006 3.875270
2007 4.036965
2008 3.883012
2009 3.527643
2010 3.071242
2011 4.497792
2012 3.091432
2013 4.172273
2014 3.403491
2015 3.319866
2018 3.422831
2019 3.418879
2020 3.432095
2021 3.522166
2022 3.384677
ggplot(winter_standard_dev_all_739_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 739 average winter temperatures for water years 1986-2021

winter MK & SS 739 (corrected)

winter_sd_mk_739_ad <- mk.test(winter_standard_dev_all_739_ad$sd_2)
print(winter_sd_mk_739_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_739_ad$sd_2
## z = -0.71364, n = 30, p-value = 0.4754
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -41.00000000 3141.66666667   -0.09425287
winter_sd_sens_739_ad <- sens.slope(winter_standard_dev_all_739_ad$sd_2)
print(winter_sd_sens_739_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_739_ad$sd_2
## z = -0.71364, n = 30, p-value = 0.4754
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02024094  0.01056628
## sample estimates:
##  Sen's slope 
## -0.007411266

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_739 <- standard_dev_739 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_739 <- spring_standard_dev_all_739 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_739 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 2.853686
1990 2.138827
1991 2.775886
1992 2.077677
1995 2.610559
1996 3.229158
1997 3.207493
1998 2.699241
1999 2.977845
2000 2.947054
2001 2.873354
2002 2.429623
2003 2.963093
2004 2.309320
2005 2.560490
2006 2.268317
2007 2.615547
2008 2.557178
2009 2.733545
2010 3.252934
2011 3.120808
2012 2.644980
2013 2.777661
2014 3.008622
2015 2.641330
2018 2.333033
2019 3.026996
2020 1.933506
2021 2.304199
2022 2.837370
ggplot(spring_standard_dev_all_739, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 739 average spring temperatures for water years 2005-2021

spring MK & SS for 739 (non-corrected)

spring_sd_mk_739 <- mk.test(spring_standard_dev_all_739$sd_2)
print(spring_sd_mk_739)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_739$sd_2
## z = -0.28546, n = 30, p-value = 0.7753
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -17.00000000 3141.66666667   -0.03908046
spring_sd_sens_739 <- sens.slope(spring_standard_dev_all_739$sd_2)
print(spring_sd_sens_739)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_739$sd_2
## z = -0.28546, n = 30, p-value = 0.7753
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02094255  0.01207004
## sample estimates:
##  Sen's slope 
## -0.003687951

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_739 <- standard_dev_739 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_739 <- fall_standard_dev_all_739 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_739 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 1.699299
1990 2.359939
1991 2.822380
1992 2.769060
1995 2.507008
1996 2.862110
1997 3.082019
1998 3.047576
1999 2.183057
2000 2.232646
2001 1.796052
2002 1.803189
2003 2.120000
2004 2.566146
2005 2.022253
2006 2.668114
2007 2.123671
2008 2.364362
2009 2.242287
2010 2.934994
2011 1.903207
2012 1.997430
2013 2.222921
2014 2.620217
2015 1.785991
2018 2.087553
2019 2.144622
2020 3.009591
2021 2.035968
2022 2.311012
ggplot(fall_standard_dev_all_739, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 739 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 739 (non-corrected)

fall_sd_mk_739 <- mk.test(fall_standard_dev_all_739$sd_2)
print(fall_sd_mk_739)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_739$sd_2
## z = -0.92773, n = 30, p-value = 0.3535
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -53.0000000 3141.6666667   -0.1218391
fall_sd_sens_739 <- sens.slope(fall_standard_dev_all_739$sd_2)
print(fall_sd_sens_739)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_739$sd_2
## z = -0.92773, n = 30, p-value = 0.3535
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02890703  0.01029220
## sample estimates:
## Sen's slope 
## -0.00938187

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_739_ad <- standard_dev_739_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_739_ad <- spring_standard_dev_all_739_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_739_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 2.678855
1990 2.004384
1991 2.597151
1992 1.952727
1995 2.432987
1996 2.938428
1997 2.944910
1998 2.449698
1999 2.738092
2000 2.671987
2001 2.602434
2002 2.220277
2003 2.677019
2004 2.127855
2005 2.583212
2006 2.268938
2007 2.601644
2008 2.565214
2009 2.761397
2010 3.260857
2011 3.095893
2012 2.631079
2013 2.779142
2014 3.020081
2015 2.595060
2018 2.332841
2019 2.971046
2020 1.952218
2021 2.282202
2022 2.841108
ggplot(spring_standard_dev_all_739_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 739 average spring temperatures for water years 1986-2021

spring MK & SS 739 (corrected)

spring_sd_mk_739_ad <- mk.test(spring_standard_dev_all_739_ad$sd_2)
print(spring_sd_mk_739_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_739_ad$sd_2
## z = 0.85637, n = 30, p-value = 0.3918
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   49.0000000 3141.6666667    0.1126437
spring_sd_sens_739_ad <- sens.slope(spring_standard_dev_all_739_ad$sd_2)
print(spring_sd_sens_739_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_739_ad$sd_2
## z = 0.85637, n = 30, p-value = 0.3918
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.008939462  0.020851865
## sample estimates:
## Sen's slope 
## 0.006838149

Fall

fall_standard_dev_all_739_ad <- standard_dev_739_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_739_ad <- fall_standard_dev_all_739_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_739_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 1.631390
1990 2.207060
1991 2.671550
1992 2.621438
1995 2.223763
1996 2.658199
1997 2.780195
1998 2.740255
1999 2.033324
2000 2.044412
2001 1.611853
2002 1.658453
2003 1.933685
2004 2.687304
2005 2.051940
2006 2.594794
2007 2.168900
2008 2.322612
2009 2.205355
2010 2.982465
2011 1.906270
2012 2.019806
2013 2.241640
2014 2.660994
2015 1.744141
2018 2.053433
2019 2.192324
2020 3.050006
2021 2.046994
2022 2.348168
ggplot(fall_standard_dev_all_739_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 739 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 739 (corrected)

fall_sd_mk_739_ad <- mk.test(fall_standard_dev_all_739_ad$sd_2)
print(fall_sd_mk_739_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_739_ad$sd_2
## z = 0.071364, n = 30, p-value = 0.9431
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 5.000000e+00 3.141667e+03 1.149425e-02
fall_sd_sens_739_ad <- sens.slope(fall_standard_dev_all_739_ad$sd_2)
print(fall_sd_sens_739_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_739_ad$sd_2
## z = 0.071364, n = 30, p-value = 0.9431
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01996776  0.01780942
## sample estimates:
##  Sen's slope 
## 0.0001553124

Slumgullion 762

Morrisey 6/26/2006

snotel_762 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "762")
#str(snotel_762) # check the date, usually a character.  

snotel_762$Date <- as.Date(snotel_762$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_762_clean <- snotel_762 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_762_clean <- snotel_762_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_762_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_762_clean <- snotel_762_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_762_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
#snotel_762_cull_count <- snotel_762_clean %>% 
#  filter(temperature_min > -40) %>% 
#  count(waterYear)

#snotel_762_cull_count

# filtering for too few observations in a year
snotel_762_cull_count_days <- snotel_762_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_762_cull_count_days
## # A tibble: 5 x 2
## # Groups:   waterYear [5]
##   waterYear     n
##       <dbl> <int>
## 1      1980    43
## 2      1982     1
## 3      1983   319
## 4      1994   331
## 5      2003   337

1980, 1982, 1994, 2003 need to be culled. 1995 maximums are less than the minimums.

snotel_762_clean_culled <- snotel_762_clean %>% 
  filter(waterYear != "1980" & waterYear != "1981" & waterYear != "1982" & waterYear != "1983" & waterYear != "1994" & waterYear != "1995" & waterYear != "2003")# & waterYear != "2017" & waterYear != "1993" & waterYear != "1994" & waterYear != "2021" & waterYear != "2022") & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_762_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_762_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_762_xts <- xts(snotel_762_clean_culled$temperature_mean, order.by = snotel_762_clean_culled$Date)

dygraph(temp_762_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
#snotel_762_clean_culled <- snotel_762_clean_culled %>% 
#  filter(temperature_mean < 19.3)

temp_762_xts <- xts(snotel_762_clean_culled$temperature_mean, order.by = snotel_762_clean_culled$Date)

dygraph(temp_762_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Slumgullion 762

Morrisey 6/26/2006

snotel_762_adjusted <- snotel_762_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2006-06-26", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

762 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_762 <- snotel_762_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_762 <- yearly_wy_aver_762 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(temperature_mean))

#average mean temperature by day for the period of record:

daily_wy_aver_762 <- daily_wy_aver_762 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_762$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_762 <-daily_wy_aver_762 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_762$date_temp <- signif(daily_wy_aver2_762$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_762, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

762 SD

standard_dev_762 <- daily_wy_aver_762 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_762 <- standard_dev_762 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_762 <- standard_dev_all_762 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_762 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 3.674754
1985 3.811974
1986 3.779033
1987 3.397189
1988 3.492532
1989 4.651110
1990 3.520505
1991 3.585690
1992 3.292746
1993 3.183632
1996 3.792566
1997 3.636680
1998 3.466194
1999 3.555503
2000 3.717397
2001 3.590073
2002 3.453558
2004 3.871442
2005 3.375428
2006 3.543733
2007 3.608661
2008 3.535416
2009 3.591799
2010 3.448849
2011 3.796410
2012 3.298442
2013 3.838710
2014 3.472603
2015 3.541464
2016 3.518881
2017 3.770665
2018 3.306869
2019 3.381724
2020 3.554739
2021 3.572869
2022 3.711409
ggplot(standard_dev_all_762, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 762 average temperatures for water years 2005-2021

MK & SS for 762 (non-corrected)

sd_mk_762 <- mk.test(standard_dev_all_762$sd_2)
print(sd_mk_762)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_762$sd_2
## z = -0.66742, n = 36, p-value = 0.5045
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -50.00000000 5390.00000000   -0.07936508
sd_sens_762 <- sens.slope(standard_dev_all_762$sd_2)
print(sd_sens_762)
## 
##  Sen's slope
## 
## data:  standard_dev_all_762$sd_2
## z = -0.66742, n = 36, p-value = 0.5045
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.009109485  0.004336017
## sample estimates:
##  Sen's slope 
## -0.002284966

Corrected

762 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_762_ad <- snotel_762_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_762_ad <- yearly_wy_aver_762_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_762_ad <- daily_wy_aver_762_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_762_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_762_ad <-daily_wy_aver_762_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_762_ad$date_temp_ad <- signif(daily_wy_aver2_762_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_762_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

762 SS (corrected)

standard_dev_762_ad <- daily_wy_aver_762_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_762_ad <- standard_dev_762_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_762_ad <- standard_dev_all_762_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_762_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 3.512195
1985 3.650211
1986 3.653822
1987 3.237700
1988 3.327910
1989 4.441340
1990 3.361853
1991 3.460118
1992 3.158882
1993 3.044969
1996 3.616153
1997 3.479059
1998 3.273680
1999 3.447850
2000 3.544296
2001 3.401704
2002 3.235946
2004 3.703860
2005 3.203425
2006 3.429340
2007 3.602023
2008 3.570293
2009 3.547798
2010 3.482463
2011 3.811326
2012 3.303977
2013 3.870843
2014 3.473381
2015 3.475047
2016 3.512692
2017 3.731968
2018 3.278770
2019 3.404475
2020 3.577477
2021 3.597633
2022 3.682716
ggplot(standard_dev_all_762_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 762 average temperatures for water years 1986-2021

MK & SS 762 (corrected)

sd_mk_762_ad <- mk.test(standard_dev_all_762_ad$sd_2)
print(sd_mk_762_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_762_ad$sd_2
## z = 1.2395, n = 36, p-value = 0.2152
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   92.0000000 5390.0000000    0.1460317
sd_sens_762_ad <- sens.slope(standard_dev_all_762_ad$sd_2)
print(sd_sens_762_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_762_ad$sd_2
## z = 1.2395, n = 36, p-value = 0.2152
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.002536221  0.011219530
## sample estimates:
## Sen's slope 
## 0.004482458

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_762 <- standard_dev_762 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_762 <- summer_standard_dev_all_762 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_762 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 2.121049
1985 2.429970
1986 2.295256
1987 2.015392
1988 2.103816
1989 2.638447
1990 2.466941
1991 1.921651
1992 2.410631
1993 2.352126
1996 2.084212
1997 2.084974
1998 2.570170
1999 1.847520
2000 2.072027
2001 2.428049
2002 2.264936
2004 2.545177
2005 2.609877
2006 2.297128
2007 2.104742
2008 1.997282
2009 2.283337
2010 2.259447
2011 1.760714
2012 1.854126
2013 2.065839
2014 1.764311
2015 2.192404
2016 2.463019
2017 1.812810
2018 1.841583
2019 2.328065
2020 2.333086
2021 2.732422
2022 2.329927
ggplot(summer_standard_dev_all_762, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 762 average summer temperatures for water years 2005-2021

summer MK & SS for 762 (non-corrected)

summer_sd_mk_762 <- mk.test(summer_standard_dev_all_762$sd_2)
print(summer_sd_mk_762)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_762$sd_2
## z = -0.74915, n = 36, p-value = 0.4538
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -56.00000000 5390.00000000   -0.08888889
summer_sd_sens_762 <- sens.slope(summer_standard_dev_all_762$sd_2)
print(summer_sd_sens_762)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_762$sd_2
## z = -0.74915, n = 36, p-value = 0.4538
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.011636016  0.007080472
## sample estimates:
##  Sen's slope 
## -0.003140367

Winter

winter_standard_dev_all_762 <- standard_dev_762 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_762 <- winter_standard_dev_all_762 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_762 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 4.370694
1985 4.225743
1986 4.696822
1987 4.191253
1988 4.254841
1989 5.021854
1990 4.326679
1991 4.497057
1992 3.365838
1993 3.678095
1996 4.368633
1997 4.249374
1998 3.941921
1999 4.069827
2000 4.449323
2001 4.200587
2002 4.081446
2004 4.729103
2005 4.024756
2006 4.385095
2007 4.543422
2008 4.339487
2009 4.302089
2010 3.730643
2011 4.814947
2012 4.066486
2013 5.025098
2014 3.908495
2015 4.156322
2016 4.395120
2017 4.483070
2018 4.082108
2019 3.916754
2020 3.808953
2021 4.089753
2022 4.342888
ggplot(winter_standard_dev_all_762, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 762 average winter temperatures for water years 2005-2021

winter MK & SS for 762 (non-corrected)

winter_sd_mk_762 <- mk.test(winter_standard_dev_all_762$sd_2)
print(winter_sd_mk_762)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_762$sd_2
## z = -0.72191, n = 36, p-value = 0.4704
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -54.00000000 5390.00000000   -0.08571429
winter_sd_sens_762 <- sens.slope(winter_standard_dev_all_762$sd_2)
print(winter_sd_sens_762)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_762$sd_2
## z = -0.72191, n = 36, p-value = 0.4704
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.015690916  0.005833482
## sample estimates:
##  Sen's slope 
## -0.005270973

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_762_ad <- standard_dev_762_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_762_ad <- summer_standard_dev_all_762_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_762_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 1.909698
1985 2.197765
1986 2.075617
1987 1.810283
1988 1.896899
1989 2.360066
1990 2.225531
1991 1.730781
1992 2.170201
1993 2.128094
1996 1.874327
1997 1.884319
1998 2.307431
1999 1.668918
2000 1.884227
2001 2.200421
2002 2.039733
2004 2.305431
2005 2.331903
2006 2.232855
2007 2.117850
2008 2.004622
2009 2.310604
2010 2.243587
2011 1.753982
2012 1.822503
2013 2.042784
2014 1.763936
2015 2.184494
2016 2.446661
2017 1.791670
2018 1.817822
2019 2.330936
2020 2.331795
2021 2.704721
2022 2.293688
ggplot(summer_standard_dev_all_762_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 762 average summer temperatures for water years 1986-2021

summer MK & SS 762 (corrected)

summer_sd_mk_762_ad <- mk.test(summer_standard_dev_all_762_ad$sd_2)
print(summer_sd_mk_762_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_762_ad$sd_2
## z = 1.294, n = 36, p-value = 0.1957
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##           S        varS         tau 
##   96.000000 5390.000000    0.152381
summer_sd_sens_762_ad <- sens.slope(summer_standard_dev_all_762_ad$sd_2)
print(summer_sd_sens_762_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_762_ad$sd_2
## z = 1.294, n = 36, p-value = 0.1957
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.002563169  0.013366036
## sample estimates:
## Sen's slope 
## 0.005474466

Winter

winter_standard_dev_all_762_ad <- standard_dev_762_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_762_ad <- winter_standard_dev_all_762_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_762_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 4.286996
1985 4.189401
1986 4.565600
1987 4.084134
1988 4.167264
1989 4.885547
1990 4.217138
1991 4.420426
1992 3.283415
1993 3.602860
1996 4.258824
1997 4.116452
1998 3.851682
1999 3.953071
2000 4.302424
2001 4.116758
2002 3.965718
2004 4.610020
2005 3.931681
2006 4.290038
2007 4.545426
2008 4.352449
2009 4.295278
2010 3.734715
2011 4.813739
2012 4.062357
2013 5.025155
2014 3.907849
2015 4.154451
2016 4.391334
2017 4.487506
2018 4.077482
2019 3.908770
2020 3.813019
2021 4.086766
2022 4.341013
ggplot(winter_standard_dev_all_762_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 762 average winter temperatures for water years 1986-2021

winter MK & SS 762 (corrected)

winter_sd_mk_762_ad <- mk.test(winter_standard_dev_all_762_ad$sd_2)
print(winter_sd_mk_762_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_762_ad$sd_2
## z = -0.17707, n = 36, p-value = 0.8595
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -14.00000000 5390.00000000   -0.02222222
winter_sd_sens_762_ad <- sens.slope(winter_standard_dev_all_762_ad$sd_2)
print(winter_sd_sens_762_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_762_ad$sd_2
## z = -0.17707, n = 36, p-value = 0.8595
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01181957  0.01012957
## sample estimates:
##  Sen's slope 
## -0.001292568

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_762 <- standard_dev_762 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_762 <- spring_standard_dev_all_762 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_762 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 4.534628
1985 3.305359
1986 3.256485
1987 3.229213
1988 3.888692
1989 3.720889
1990 2.637364
1991 3.659630
1992 3.166917
1993 2.978632
1996 4.011959
1997 3.586347
1998 3.256678
1999 3.647316
2000 3.765191
2001 3.575043
2002 2.793251
2004 3.165738
2005 3.405809
2006 2.984876
2007 3.358183
2008 3.444390
2009 3.263000
2010 3.742168
2011 3.797822
2012 3.206662
2013 3.286118
2014 3.999419
2015 3.055162
2016 3.029008
2017 3.977395
2018 3.172001
2019 3.595530
2020 3.136391
2021 3.278940
2022 3.832348
ggplot(spring_standard_dev_all_762, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 762 average spring temperatures for water years 2005-2021

spring MK & SS for 762 (non-corrected)

spring_sd_mk_762 <- mk.test(spring_standard_dev_all_762$sd_2)
print(spring_sd_mk_762)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_762$sd_2
## z = -0.34052, n = 36, p-value = 0.7335
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -26.00000000 5390.00000000   -0.04126984
spring_sd_sens_762 <- sens.slope(spring_standard_dev_all_762$sd_2)
print(spring_sd_sens_762)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_762$sd_2
## z = -0.34052, n = 36, p-value = 0.7335
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01832072  0.01195427
## sample estimates:
##  Sen's slope 
## -0.002109237

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_762 <- standard_dev_762 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_762 <- fall_standard_dev_all_762 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_762 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 2.377087
1985 3.330143
1986 2.818994
1987 2.495534
1988 2.125549
1989 6.341396
1990 3.482498
1991 2.753827
1992 3.629274
1993 2.220687
1996 3.791520
1997 3.822974
1998 3.347107
1999 2.918635
2000 3.248858
2001 2.776079
2002 2.809535
2004 3.721294
2005 2.416210
2006 2.457190
2007 2.598477
2008 3.086035
2009 3.180909
2010 3.867847
2011 2.810314
2012 2.654749
2013 2.772447
2014 3.550187
2015 2.578622
2016 2.519704
2017 3.301218
2018 2.835611
2019 2.874401
2020 4.545681
2021 3.086625
2022 3.260659
ggplot(fall_standard_dev_all_762, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 762 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 762 (non-corrected)

fall_sd_mk_762 <- mk.test(fall_standard_dev_all_762$sd_2)
print(fall_sd_mk_762)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_762$sd_2
## z = 0.53121, n = 36, p-value = 0.5953
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 4.000000e+01 5.390000e+03 6.349206e-02
fall_sd_sens_762 <- sens.slope(fall_standard_dev_all_762$sd_2)
print(fall_sd_sens_762)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_762$sd_2
## z = 0.53121, n = 36, p-value = 0.5953
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01719846  0.02422900
## sample estimates:
## Sen's slope 
## 0.003929009

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_762_ad <- standard_dev_762_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_762_ad <- spring_standard_dev_all_762_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_762_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 4.217420
1985 3.099156
1986 3.043760
1987 3.023156
1988 3.629927
1989 3.461828
1990 2.482044
1991 3.448855
1992 2.965577
1993 2.774256
1996 3.726126
1997 3.365482
1998 3.027657
1999 3.434762
2000 3.478866
2001 3.321006
2002 2.585246
2004 2.949556
2005 3.150812
2006 2.769435
2007 3.344610
2008 3.454174
2009 3.288924
2010 3.751667
2011 3.781915
2012 3.191883
2013 3.297758
2014 4.006456
2015 3.003631
2016 3.013070
2017 3.954538
2018 3.201764
2019 3.537229
2020 3.160039
2021 3.259249
2022 3.841219
ggplot(spring_standard_dev_all_762_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 762 average spring temperatures for water years 1986-2021

spring MK & SS 762 (corrected)

spring_sd_mk_762_ad <- mk.test(spring_standard_dev_all_762_ad$sd_2)
print(spring_sd_mk_762_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_762_ad$sd_2
## z = 0.85812, n = 36, p-value = 0.3908
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   64.0000000 5390.0000000    0.1015873
spring_sd_sens_762_ad <- sens.slope(spring_standard_dev_all_762_ad$sd_2)
print(spring_sd_sens_762_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_762_ad$sd_2
## z = 0.85812, n = 36, p-value = 0.3908
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.008185906  0.021600715
## sample estimates:
## Sen's slope 
##  0.00634137

Fall

fall_standard_dev_all_762_ad <- standard_dev_762_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_762_ad <- fall_standard_dev_all_762_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_762_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 2.220585
1985 3.114451
1986 2.656441
1987 2.337290
1988 1.988422
1989 6.018008
1990 3.195529
1991 2.581586
1992 3.402576
1993 2.076028
1996 3.549068
1997 3.550354
1998 3.079443
1999 2.724953
2000 3.022949
2001 2.521987
2002 2.623049
2004 3.476575
2005 2.213750
2006 2.552964
2007 2.644461
2008 3.055885
2009 3.149187
2010 3.932891
2011 2.803823
2012 2.664549
2013 2.780565
2014 3.606056
2015 2.541312
2016 2.488523
2017 3.252401
2018 2.810671
2019 2.929247
2020 4.583934
2021 3.088046
2022 3.310170
ggplot(fall_standard_dev_all_762_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 762 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 762 (corrected)

fall_sd_mk_762_ad <- mk.test(fall_standard_dev_all_762_ad$sd_2)
print(fall_sd_mk_762_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_762_ad$sd_2
## z = 1.3485, n = 36, p-value = 0.1775
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  100.0000000 5390.0000000    0.1587302
fall_sd_sens_762_ad <- sens.slope(fall_standard_dev_all_762_ad$sd_2)
print(fall_sd_sens_762_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_762_ad$sd_2
## z = 1.3485, n = 36, p-value = 0.1775
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.006444124  0.030542337
## sample estimates:
## Sen's slope 
##  0.01348365

Spud Mountain 780

Morrisey 6/28/2004

snotel_780 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "780")
#str(snotel_780) # check the date, usually a character.  

snotel_780$Date <- as.Date(snotel_780$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_780_clean <- snotel_780 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_780_clean <- snotel_780_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_780_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_780_clean <- snotel_780_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_780_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
#snotel_780_cull_count <- snotel_780_clean %>% 
#  filter(temperature_min > -40) %>% 
#  count(waterYear)

#snotel_780_cull_count

# filtering for too few observations in a year
snotel_780_cull_count_days <- snotel_780_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_780_cull_count_days
## # A tibble: 8 x 2
## # Groups:   waterYear [8]
##   waterYear     n
##       <dbl> <int>
## 1      1987   315
## 2      1994   336
## 3      1998   309
## 4      2009   342
## 5      2011   337
## 6      2013   336
## 7      2016   331
## 8      2017   324

1987, 1994, 1998, 2009, 2011, 2013, 2016, 2017 need to be culled.

snotel_780_clean_culled <- snotel_780_clean %>% 
  filter(waterYear != "1987" & waterYear != "1994" & waterYear != "1998" & waterYear != "2009" & waterYear != "2011" & waterYear != "2013" & waterYear != "2016" & waterYear != "2017")# & waterYear != "1993" & waterYear != "1994" & waterYear != "2021" & waterYear != "2022") & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_780_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_780_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_780_xts <- xts(snotel_780_clean_culled$temperature_mean, order.by = snotel_780_clean_culled$Date)

dygraph(temp_780_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
#snotel_780_clean_culled <- snotel_780_clean_culled %>% 
#  filter(temperature_mean < 19.3)

temp_780_xts <- xts(snotel_780_clean_culled$temperature_mean, order.by = snotel_780_clean_culled$Date)

dygraph(temp_780_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Spud Mountain 780

Morrisey 6/28/2004

snotel_780_adjusted <- snotel_780_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2004-06-28", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

780 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_780 <- snotel_780_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_780 <- yearly_wy_aver_780 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(temperature_mean))

#average mean temperature by day for the period of record:

daily_wy_aver_780 <- daily_wy_aver_780 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_780$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_780 <-daily_wy_aver_780 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_780$date_temp <- signif(daily_wy_aver2_780$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_780, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

780 SD

standard_dev_780 <- daily_wy_aver_780 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_780 <- standard_dev_780 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_780 <- standard_dev_all_780 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_780 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 3.473865
1989 3.919287
1990 3.440384
1991 3.521589
1992 3.176267
1993 3.152277
1995 3.688411
1996 3.799151
1997 3.553287
1999 3.449081
2000 3.414623
2001 3.553822
2002 3.520936
2003 3.407037
2004 3.668567
2005 3.199943
2006 3.396991
2007 3.519768
2008 3.359561
2010 3.256492
2012 3.161424
2014 3.341380
2015 3.507262
2018 3.109592
2019 3.225546
2020 3.222803
2021 3.338262
2022 3.387365
ggplot(standard_dev_all_780, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 780 average temperatures for water years 2005-2021

MK & SS for 780 (non-corrected)

sd_mk_780 <- mk.test(standard_dev_all_780$sd_2)
print(sd_mk_780)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_780$sd_2
## z = -2.7462, n = 28, p-value = 0.00603
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -140.0000000 2562.0000000   -0.3703704
sd_sens_780 <- sens.slope(standard_dev_all_780$sd_2)
print(sd_sens_780)
## 
##  Sen's slope
## 
## data:  standard_dev_all_780$sd_2
## z = -2.7462, n = 28, p-value = 0.00603
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.020599851 -0.003031605
## sample estimates:
## Sen's slope 
## -0.01120797

Corrected

780 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_780_ad <- snotel_780_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_780_ad <- yearly_wy_aver_780_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_780_ad <- daily_wy_aver_780_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_780_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_780_ad <-daily_wy_aver_780_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_780_ad$date_temp_ad <- signif(daily_wy_aver2_780_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_780_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

780 SS (corrected)

standard_dev_780_ad <- daily_wy_aver_780_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_780_ad <- standard_dev_780_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_780_ad <- standard_dev_all_780_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_780_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 3.270878
1989 3.707986
1990 3.245153
1991 3.347662
1992 3.016828
1993 2.950500
1995 3.481932
1996 3.583045
1997 3.353276
1999 3.310422
2000 3.198771
2001 3.324245
2002 3.256083
2003 3.176983
2004 3.521770
2005 3.186087
2006 3.356556
2007 3.511866
2008 3.388905
2010 3.285941
2012 3.169381
2014 3.316545
2015 3.423163
2018 3.061681
2019 3.244566
2020 3.251227
2021 3.359361
2022 3.356065
ggplot(standard_dev_all_780_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 780 average temperatures for water years 1986-2021

MK & SS 780 (corrected)

sd_mk_780_ad <- mk.test(standard_dev_all_780_ad$sd_2)
print(sd_mk_780_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_780_ad$sd_2
## z = -0.17781, n = 28, p-value = 0.8589
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -10.00000000 2562.00000000   -0.02645503
sd_sens_780_ad <- sens.slope(standard_dev_all_780_ad$sd_2)
print(sd_sens_780_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_780_ad$sd_2
## z = -0.17781, n = 28, p-value = 0.8589
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.010545398  0.006590586
## sample estimates:
##   Sen's slope 
## -0.0008728816

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_780 <- standard_dev_780 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_780 <- summer_standard_dev_all_780 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_780 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 1.988875
1989 2.380976
1990 2.638450
1991 1.953262
1992 2.334022
1993 2.650819
1995 3.026132
1996 2.120107
1997 2.031936
1999 2.222751
2000 1.738164
2001 2.306372
2002 2.201926
2003 2.280899
2004 2.402414
2005 2.144601
2006 2.099693
2007 2.060096
2008 1.941681
2010 2.229146
2012 1.561106
2014 1.727293
2015 2.194333
2018 1.766647
2019 2.199362
2020 2.162959
2021 2.450495
2022 2.148514
ggplot(summer_standard_dev_all_780, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 780 average summer temperatures for water years 2005-2021

summer MK & SS for 780 (non-corrected)

summer_sd_mk_780 <- mk.test(summer_standard_dev_all_780$sd_2)
print(summer_sd_mk_780)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_780$sd_2
## z = -1.4027, n = 28, p-value = 0.1607
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -72.0000000 2562.0000000   -0.1904762
summer_sd_sens_780 <- sens.slope(summer_standard_dev_all_780$sd_2)
print(summer_sd_sens_780)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_780$sd_2
## z = -1.4027, n = 28, p-value = 0.1607
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.023760891  0.004189474
## sample estimates:
##  Sen's slope 
## -0.009247362

Winter

winter_standard_dev_all_780 <- standard_dev_780 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_780 <- winter_standard_dev_all_780 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_780 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 4.130348
1989 4.806906
1990 4.200557
1991 4.177242
1992 3.183074
1993 3.475583
1995 4.220426
1996 4.395302
1997 4.092383
1999 3.788688
2000 4.079260
2001 4.183597
2002 4.122931
2003 3.864654
2004 4.373582
2005 3.915684
2006 4.132860
2007 4.445902
2008 4.080756
2010 3.501173
2012 3.846661
2014 3.821079
2015 3.973040
2018 3.867386
2019 3.624004
2020 3.594809
2021 3.891228
2022 3.976906
ggplot(winter_standard_dev_all_780, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 780 average winter temperatures for water years 2005-2021

winter MK & SS for 780 (non-corrected)

winter_sd_mk_780 <- mk.test(winter_standard_dev_all_780$sd_2)
print(winter_sd_mk_780)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_780$sd_2
## z = -1.9954, n = 28, p-value = 0.046
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -102.0000000 2562.0000000   -0.2698413
winter_sd_sens_780 <- sens.slope(winter_standard_dev_all_780$sd_2)
print(winter_sd_sens_780)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_780$sd_2
## z = -1.9954, n = 28, p-value = 0.046
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.0266974619 -0.0006180869
## sample estimates:
## Sen's slope 
## -0.01470937

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_780_ad <- standard_dev_780_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_780_ad <- summer_standard_dev_all_780_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_780_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 1.785223
1989 2.122444
1990 2.378106
1991 1.760736
1992 2.097471
1993 2.372857
1995 2.717873
1996 1.910416
1997 1.827132
1999 2.006143
2000 1.570396
2001 2.084832
2002 1.979213
2003 2.034661
2004 2.296824
2005 2.191623
2006 2.073056
2007 2.064281
2008 1.945670
2010 2.214610
2012 1.529022
2014 1.721658
2015 2.183925
2018 1.746364
2019 2.200068
2020 2.162637
2021 2.418528
2022 2.117568
ggplot(summer_standard_dev_all_780_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 780 average summer temperatures for water years 1986-2021

summer MK & SS 780 (corrected)

summer_sd_mk_780_ad <- mk.test(summer_standard_dev_all_780_ad$sd_2)
print(summer_sd_mk_780_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_780_ad$sd_2
## z = 0.29635, n = 28, p-value = 0.767
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 1.600000e+01 2.562000e+03 4.232804e-02
summer_sd_sens_780_ad <- sens.slope(summer_standard_dev_all_780_ad$sd_2)
print(summer_sd_sens_780_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_780_ad$sd_2
## z = 0.29635, n = 28, p-value = 0.767
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01042151  0.01538651
## sample estimates:
## Sen's slope 
## 0.003154037

Winter

winter_standard_dev_all_780_ad <- standard_dev_780_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_780_ad <- winter_standard_dev_all_780_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_780_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 3.987990
1989 4.643449
1990 4.027266
1991 4.047699
1992 3.056594
1993 3.368587
1995 4.058435
1996 4.216864
1997 3.929135
1999 3.636506
2000 3.878162
2001 4.048157
2002 3.955572
2003 3.715181
2004 4.205889
2005 3.895432
2006 4.120208
2007 4.452047
2008 4.100999
2010 3.503388
2012 3.841190
2014 3.813675
2015 3.972531
2018 3.860096
2019 3.610733
2020 3.595025
2021 3.881752
2022 3.977116
ggplot(winter_standard_dev_all_780_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 780 average winter temperatures for water years 1986-2021

winter MK & SS 780 (corrected)

winter_sd_mk_780_ad <- mk.test(winter_standard_dev_all_780_ad$sd_2)
print(winter_sd_mk_780_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_780_ad$sd_2
## z = -1.0866, n = 28, p-value = 0.2772
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -56.0000000 2562.0000000   -0.1481481
winter_sd_sens_780_ad <- sens.slope(winter_standard_dev_all_780_ad$sd_2)
print(winter_sd_sens_780_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_780_ad$sd_2
## z = -1.0866, n = 28, p-value = 0.2772
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.018933359  0.006806957
## sample estimates:
##  Sen's slope 
## -0.007022252

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_780 <- standard_dev_780 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_780 <- spring_standard_dev_all_780 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_780 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 3.940866
1989 4.017098
1990 2.828146
1991 3.722924
1992 3.049712
1993 2.829647
1995 3.232653
1996 3.948352
1997 3.713405
1999 3.596673
2000 3.729713
2001 3.610137
2002 2.895630
2003 3.674120
2004 2.929562
2005 3.277577
2006 2.761450
2007 3.200510
2008 3.316701
2010 3.572509
2012 3.189897
2014 3.806342
2015 3.193463
2018 2.951363
2019 3.728605
2020 2.639035
2021 2.894008
2022 3.181776
ggplot(spring_standard_dev_all_780, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 780 average spring temperatures for water years 2005-2021

spring MK & SS for 780 (non-corrected)

spring_sd_mk_780 <- mk.test(spring_standard_dev_all_780$sd_2)
print(spring_sd_mk_780)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_780$sd_2
## z = -1.7583, n = 28, p-value = 0.07869
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -90.0000000 2562.0000000   -0.2380952
spring_sd_sens_780 <- sens.slope(spring_standard_dev_all_780$sd_2)
print(spring_sd_sens_780)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_780$sd_2
## z = -1.7583, n = 28, p-value = 0.07869
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.039670322  0.001783057
## sample estimates:
## Sen's slope 
## -0.01918929

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_780 <- standard_dev_780 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_780 <- fall_standard_dev_all_780 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_780 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 2.631417
1989 2.530670
1990 3.036563
1991 3.253054
1992 3.701839
1993 2.840297
1995 3.123312
1996 3.847084
1997 3.750558
1999 2.744696
2000 3.098304
2001 2.788667
2002 2.787253
2003 3.093741
2004 3.622349
2005 2.238842
2006 2.971628
2007 2.604753
2008 3.006782
2010 3.573457
2012 2.924032
2014 3.113513
2015 2.479303
2018 2.435022
2019 2.831042
2020 3.896512
2021 3.012137
2022 3.276546
ggplot(fall_standard_dev_all_780, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 780 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 780 (non-corrected)

fall_sd_mk_780 <- mk.test(fall_standard_dev_all_780$sd_2)
print(fall_sd_mk_780)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_780$sd_2
## z = -0.098783, n = 28, p-value = 0.9213
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##   -6.00000000 2562.00000000   -0.01587302
fall_sd_sens_780 <- sens.slope(fall_standard_dev_all_780$sd_2)
print(fall_sd_sens_780)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_780$sd_2
## z = -0.098783, n = 28, p-value = 0.9213
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02251526  0.02168715
## sample estimates:
##  Sen's slope 
## -0.001215913

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_780_ad <- standard_dev_780_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_780_ad <- spring_standard_dev_all_780_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_780_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 3.662013
1989 3.720561
1990 2.639072
1991 3.481729
1992 2.839262
1993 2.605972
1995 3.027587
1996 3.624850
1997 3.440074
1999 3.356177
2000 3.408131
2001 3.315233
2002 2.654180
2003 3.372475
2004 2.700185
2005 3.299948
2006 2.766285
2007 3.185510
2008 3.316730
2010 3.584815
2012 3.175278
2014 3.805623
2015 3.139833
2018 2.961119
2019 3.664448
2020 2.658443
2021 2.871734
2022 3.185942
ggplot(spring_standard_dev_all_780_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 780 average spring temperatures for water years 1986-2021

spring MK & SS 780 (corrected)

spring_sd_mk_780_ad <- mk.test(spring_standard_dev_all_780_ad$sd_2)
print(spring_sd_mk_780_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_780_ad$sd_2
## z = -0.7705, n = 28, p-value = 0.441
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -40.0000000 2562.0000000   -0.1058201
spring_sd_sens_780_ad <- sens.slope(spring_standard_dev_all_780_ad$sd_2)
print(spring_sd_sens_780_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_780_ad$sd_2
## z = -0.7705, n = 28, p-value = 0.441
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02538823  0.01402337
## sample estimates:
## Sen's slope 
## -0.01071971

Fall

fall_standard_dev_all_780_ad <- standard_dev_780_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_780_ad <- fall_standard_dev_all_780_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_780_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 2.442338
1989 2.371126
1990 2.738199
1991 3.038245
1992 3.433962
1993 2.648069
1995 2.844964
1996 3.586736
1997 3.437287
1999 2.541292
2000 2.862547
2001 2.504734
2002 2.589710
2003 2.818925
2004 3.678577
2005 2.280359
2006 2.902082
2007 2.628731
2008 2.961220
2010 3.639609
2012 2.934356
2014 3.159252
2015 2.412904
2018 2.392404
2019 2.868697
2020 3.943781
2021 2.989686
2022 3.301192
ggplot(fall_standard_dev_all_780_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 780 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 780 (corrected)

fall_sd_mk_780_ad <- mk.test(fall_standard_dev_all_780_ad$sd_2)
print(fall_sd_mk_780_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_780_ad$sd_2
## z = 1.3237, n = 28, p-value = 0.1856
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   68.0000000 2562.0000000    0.1798942
fall_sd_sens_780_ad <- sens.slope(fall_standard_dev_all_780_ad$sd_2)
print(fall_sd_sens_780_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_780_ad$sd_2
## z = 1.3237, n = 28, p-value = 0.1856
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.009360858  0.029793789
## sample estimates:
## Sen's slope 
##  0.01272711

Stump Lakes 797

Morrisey 7/22/2005

snotel_797 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "797")
#str(snotel_797) # check the date, usually a character.  

snotel_797$Date <- as.Date(snotel_797$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_797_clean <- snotel_797 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_797_clean <- snotel_797_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_797_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_797_clean <- snotel_797_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 40)
ggplot(snotel_797_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
#snotel_797_cull_count <- snotel_797_clean %>% 
#  filter(temperature_min > -40) %>% 
#  count(waterYear)

#snotel_797_cull_count

# filtering for too few observations in a year
snotel_797_cull_count_days <- snotel_797_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_797_cull_count_days
## # A tibble: 5 x 2
## # Groups:   waterYear [5]
##   waterYear     n
##       <dbl> <int>
## 1      1987   267
## 2      1993   320
## 3      1994   274
## 4      2005   329
## 5      2006   327

1987, 1993, 1994, 2005, 2006 need to be culled.

snotel_797_clean_culled <- snotel_797_clean %>% 
  filter(waterYear != "1994" & waterYear != "2005" & waterYear != "2006" & waterYear != "1993" & waterYear != "1987")# & waterYear != "2021" & waterYear != "2022") & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_797_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_797_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_797_xts <- xts(snotel_797_clean_culled$temperature_mean, order.by = snotel_797_clean_culled$Date)

dygraph(temp_797_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
#snotel_797_clean_culled <- snotel_797_clean_culled %>% 
#  filter(temperature_mean < 19.3)

temp_797_xts <- xts(snotel_797_clean_culled$temperature_mean, order.by = snotel_797_clean_culled$Date)

dygraph(temp_797_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Stump Lakes 797

Morrisey 7/22/2005

snotel_797_adjusted <- snotel_797_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2005-07-22", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

797 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_797 <- snotel_797_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_797 <- yearly_wy_aver_797 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(temperature_mean))

#average mean temperature by day for the period of record:

daily_wy_aver_797 <- daily_wy_aver_797 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_797$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_797 <-daily_wy_aver_797 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_797$date_temp <- signif(daily_wy_aver2_797$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_797, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

797 SD

standard_dev_797 <- daily_wy_aver_797 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_797 <- standard_dev_797 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_797 <- standard_dev_all_797 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_797 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 3.552424
1989 5.586529
1990 3.595147
1991 4.546821
1992 6.323580
1995 3.788816
1996 3.728833
1997 3.632152
1998 3.541500
1999 3.517117
2000 3.458494
2001 3.667820
2002 4.164287
2003 4.986331
2004 5.652986
2007 3.600089
2008 3.348002
2009 3.580172
2010 3.243984
2011 3.689759
2012 3.315822
2013 3.666199
2014 3.452706
2015 3.456861
2016 3.516328
2017 3.497094
2018 3.232763
2019 3.385760
2020 3.242425
2021 3.313131
2022 3.332394
ggplot(standard_dev_all_797, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 797 average temperatures for water years 2005-2021

MK & SS for 797 (non-corrected)

sd_mk_797 <- mk.test(standard_dev_all_797$sd_2)
print(sd_mk_797)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_797$sd_2
## z = -3.8752, n = 31, p-value = 0.0001065
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -229.0000000 3461.6666667   -0.4924731
sd_sens_797 <- sens.slope(standard_dev_all_797$sd_2)
print(sd_sens_797)
## 
##  Sen's slope
## 
## data:  standard_dev_all_797$sd_2
## z = -3.8752, n = 31, p-value = 0.0001065
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.04007395 -0.01029950
## sample estimates:
## Sen's slope 
## -0.01825689

Corrected

797 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_797_ad <- snotel_797_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_797_ad <- yearly_wy_aver_797_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_797_ad <- daily_wy_aver_797_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_797_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_797_ad <-daily_wy_aver_797_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_797_ad$date_temp_ad <- signif(daily_wy_aver2_797_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_797_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

797 SS (corrected)

standard_dev_797_ad <- daily_wy_aver_797_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_797_ad <- standard_dev_797_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_797_ad <- standard_dev_all_797_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_797_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 3.379780
1989 5.130636
1990 3.411317
1991 4.188401
1992 5.916774
1995 3.586058
1996 3.545863
1997 3.442524
1998 3.318745
1999 3.394981
2000 3.269152
2001 3.454898
2002 3.830201
2003 4.674532
2004 5.241467
2007 3.589863
2008 3.371445
2009 3.537481
2010 3.272838
2011 3.695233
2012 3.323466
2013 3.681182
2014 3.432105
2015 3.381017
2016 3.505905
2017 3.463507
2018 3.193303
2019 3.394854
2020 3.266115
2021 3.328956
2022 3.304299
ggplot(standard_dev_all_797_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 797 average temperatures for water years 1986-2021

MK & SS 797 (corrected)

sd_mk_797_ad <- mk.test(standard_dev_all_797_ad$sd_2)
print(sd_mk_797_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_797_ad$sd_2
## z = -2.3795, n = 31, p-value = 0.01734
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -141.0000000 3461.6666667   -0.3032258
sd_sens_797_ad <- sens.slope(standard_dev_all_797_ad$sd_2)
print(sd_sens_797_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_797_ad$sd_2
## z = -2.3795, n = 31, p-value = 0.01734
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.029216782 -0.002072131
## sample estimates:
## Sen's slope 
## -0.01071262

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_797 <- standard_dev_797 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_797 <- summer_standard_dev_all_797 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_797 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 2.042565
1989 6.476290
1990 3.109075
1991 5.171059
1992 2.238053
1995 3.429421
1996 2.067901
1997 2.283507
1998 2.884887
1999 2.369752
2000 1.715640
2001 2.113370
2002 4.019328
2003 2.663328
2004 4.948904
2007 2.260970
2008 2.107187
2009 2.608847
2010 2.176364
2011 1.757543
2012 1.563458
2013 1.959340
2014 1.690154
2015 2.261386
2016 2.130635
2017 1.771699
2018 1.787363
2019 2.566946
2020 2.221335
2021 2.257181
2022 2.214554
ggplot(summer_standard_dev_all_797, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 797 average summer temperatures for water years 2005-2021

summer MK & SS for 797 (non-corrected)

summer_sd_mk_797 <- mk.test(summer_standard_dev_all_797$sd_2)
print(summer_sd_mk_797)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_797$sd_2
## z = -2.1755, n = 31, p-value = 0.02959
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -129.0000000 3461.6666667   -0.2774194
summer_sd_sens_797 <- sens.slope(summer_standard_dev_all_797$sd_2)
print(summer_sd_sens_797)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_797$sd_2
## z = -2.1755, n = 31, p-value = 0.02959
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.061220950 -0.001382572
## sample estimates:
## Sen's slope 
## -0.02946618

Winter

winter_standard_dev_all_797 <- standard_dev_797 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_797 <- winter_standard_dev_all_797 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_797 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 4.310485
1989 4.900114
1990 4.271251
1991 4.189411
1992 7.303716
1995 4.324014
1996 4.377801
1997 4.213191
1998 3.957725
1999 3.988903
2000 4.147959
2001 4.398802
2002 4.179460
2003 6.579290
2004 5.867413
2007 4.540425
2008 4.130466
2009 4.202908
2010 3.384034
2011 4.641840
2012 4.102148
2013 4.842957
2014 4.000003
2015 3.901573
2016 4.494405
2017 4.117087
2018 4.119443
2019 3.826578
2020 3.565103
2021 3.883205
2022 3.882831
ggplot(winter_standard_dev_all_797, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 797 average winter temperatures for water years 2005-2021

winter MK & SS for 797 (non-corrected)

winter_sd_mk_797 <- mk.test(winter_standard_dev_all_797$sd_2)
print(winter_sd_mk_797)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_797$sd_2
## z = -2.8554, n = 31, p-value = 0.004298
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -169.0000000 3461.6666667   -0.3634409
winter_sd_sens_797 <- sens.slope(winter_standard_dev_all_797$sd_2)
print(winter_sd_sens_797)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_797$sd_2
## z = -2.8554, n = 31, p-value = 0.004298
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.034685006 -0.005339105
## sample estimates:
## Sen's slope 
## -0.01760372

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_797_ad <- standard_dev_797_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_797_ad <- summer_standard_dev_all_797_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_797_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 1.829724
1989 5.867600
1990 2.803700
1991 4.665719
1992 2.001348
1995 3.079917
1996 1.859416
1997 2.047736
1998 2.580722
1999 2.129892
2000 1.548396
2001 1.905439
2002 3.640538
2003 2.373179
2004 4.475108
2007 2.252500
2008 2.104807
2009 2.610230
2010 2.178292
2011 1.746203
2012 1.556250
2013 1.939956
2014 1.692710
2015 2.251698
2016 2.150606
2017 1.773766
2018 1.782671
2019 2.547853
2020 2.213067
2021 2.248511
2022 2.207002
ggplot(summer_standard_dev_all_797_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 797 average summer temperatures for water years 1986-2021

summer MK & SS 797 (corrected)

summer_sd_mk_797_ad <- mk.test(summer_standard_dev_all_797_ad$sd_2)
print(summer_sd_mk_797_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_797_ad$sd_2
## z = -1.2237, n = 31, p-value = 0.221
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -73.0000000 3461.6666667   -0.1569892
summer_sd_sens_797_ad <- sens.slope(summer_standard_dev_all_797_ad$sd_2)
print(summer_sd_sens_797_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_797_ad$sd_2
## z = -1.2237, n = 31, p-value = 0.221
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.045460252  0.007299646
## sample estimates:
## Sen's slope 
## -0.01522058

Winter

winter_standard_dev_all_797_ad <- standard_dev_797_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_797_ad <- winter_standard_dev_all_797_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_797_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 4.200429
1989 4.770075
1990 4.137255
1991 4.102515
1992 6.700209
1995 4.198179
1996 4.240025
1997 4.065652
1998 3.837926
1999 3.859183
2000 3.991481
2001 4.287052
2002 4.053289
2003 6.165341
2004 5.596559
2007 4.544754
2008 4.150097
2009 4.195562
2010 3.390961
2011 4.636212
2012 4.090476
2013 4.836196
2014 3.993446
2015 3.898484
2016 4.485800
2017 4.128407
2018 4.110530
2019 3.812608
2020 3.565400
2021 3.877663
2022 3.886374
ggplot(winter_standard_dev_all_797_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 797 average winter temperatures for water years 1986-2021

winter MK & SS 797 (corrected)

winter_sd_mk_797_ad <- mk.test(winter_standard_dev_all_797_ad$sd_2)
print(winter_sd_mk_797_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_797_ad$sd_2
## z = -2.0396, n = 31, p-value = 0.04139
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -121.0000000 3461.6666667   -0.2602151
winter_sd_sens_797_ad <- sens.slope(winter_standard_dev_all_797_ad$sd_2)
print(winter_sd_sens_797_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_797_ad$sd_2
## z = -2.0396, n = 31, p-value = 0.04139
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.0306807934 -0.0003846686
## sample estimates:
## Sen's slope 
## -0.01226167

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_797 <- standard_dev_797 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_797 <- spring_standard_dev_all_797 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_797 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 3.808145
1989 5.146700
1990 2.810795
1991 3.921299
1992 3.419669
1995 3.264184
1996 3.853096
1997 3.644469
1998 3.332982
1999 3.625469
2000 3.809455
2001 3.773721
2002 3.702769
2003 3.790571
2004 6.116660
2007 3.327543
2008 3.207552
2009 3.287400
2010 3.756503
2011 3.948546
2012 3.265894
2013 3.095548
2014 3.964595
2015 3.177251
2016 3.141595
2017 3.991283
2018 2.932307
2019 3.832046
2020 2.582895
2021 2.947336
2022 3.269868
ggplot(spring_standard_dev_all_797, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 797 average spring temperatures for water years 2005-2021

spring MK & SS for 797 (non-corrected)

spring_sd_mk_797 <- mk.test(spring_standard_dev_all_797$sd_2)
print(spring_sd_mk_797)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_797$sd_2
## z = -1.8696, n = 31, p-value = 0.06154
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -111.0000000 3461.6666667   -0.2387097
spring_sd_sens_797 <- sens.slope(spring_standard_dev_all_797$sd_2)
print(spring_sd_sens_797)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_797$sd_2
## z = -1.8696, n = 31, p-value = 0.06154
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.0385532204  0.0002273483
## sample estimates:
## Sen's slope 
## -0.01889332

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_797 <- standard_dev_797 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_797 <- fall_standard_dev_all_797 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_797 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 2.697999
1989 2.648851
1990 3.195462
1991 3.346286
1992 6.282063
1995 3.048767
1996 3.618036
1997 3.748430
1998 3.263616
1999 2.674546
2000 2.985657
2001 2.789820
2002 2.555908
2003 3.216832
2004 3.785595
2007 2.495213
2008 2.839230
2009 3.091992
2010 3.643581
2011 2.482885
2012 3.003235
2013 2.602181
2014 3.221037
2015 2.375936
2016 2.494035
2017 2.995555
2018 2.422976
2019 2.673073
2020 4.001557
2021 2.944464
2022 3.126290
ggplot(fall_standard_dev_all_797, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 797 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 797 (non-corrected)

fall_sd_mk_797 <- mk.test(fall_standard_dev_all_797$sd_2)
print(fall_sd_mk_797)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_797$sd_2
## z = -1.3257, n = 31, p-value = 0.1849
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -79.0000000 3461.6666667   -0.1698925
fall_sd_sens_797 <- sens.slope(fall_standard_dev_all_797$sd_2)
print(fall_sd_sens_797)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_797$sd_2
## z = -1.3257, n = 31, p-value = 0.1849
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03449036  0.00849879
## sample estimates:
## Sen's slope 
## -0.01132179

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_797_ad <- standard_dev_797_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_797_ad <- spring_standard_dev_all_797_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_797_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 3.558337
1989 4.658381
1990 2.637518
1991 3.598908
1992 3.185605
1995 3.079492
1996 3.559856
1997 3.410557
1998 3.108265
1999 3.413688
2000 3.506851
2001 3.485838
2002 3.378850
2003 3.512146
2004 5.473388
2007 3.304216
2008 3.206138
2009 3.317532
2010 3.758149
2011 3.910643
2012 3.243898
2013 3.099699
2014 3.957046
2015 3.116393
2016 3.113237
2017 3.943531
2018 2.923746
2019 3.762108
2020 2.604250
2021 2.913024
2022 3.269258
ggplot(spring_standard_dev_all_797_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 797 average spring temperatures for water years 1986-2021

spring MK & SS 797 (corrected)

spring_sd_mk_797_ad <- mk.test(spring_standard_dev_all_797_ad$sd_2)
print(spring_sd_mk_797_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_797_ad$sd_2
## z = -1.1218, n = 31, p-value = 0.262
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##           S        varS         tau 
##  -67.000000 3461.666667   -0.144086
spring_sd_sens_797_ad <- sens.slope(spring_standard_dev_all_797_ad$sd_2)
print(spring_sd_sens_797_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_797_ad$sd_2
## z = -1.1218, n = 31, p-value = 0.262
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.025200787  0.009631082
## sample estimates:
## Sen's slope 
## -0.01210824

Fall

fall_standard_dev_all_797_ad <- standard_dev_797_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_797_ad <- fall_standard_dev_all_797_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_797_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 2.519023
1989 2.484178
1990 2.900876
1991 3.086225
1992 5.758493
1995 2.765781
1996 3.388084
1997 3.446062
1998 2.997838
1999 2.489854
2000 2.767894
2001 2.508582
2002 2.389843
2003 2.928972
2004 3.539040
2007 2.526496
2008 2.798615
2009 3.049607
2010 3.692800
2011 2.493400
2012 3.007929
2013 2.594416
2014 3.258541
2015 2.331632
2016 2.468456
2017 2.947694
2018 2.384472
2019 2.707495
2020 4.041013
2021 2.940204
2022 3.157660
ggplot(fall_standard_dev_all_797_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 797 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 797 (corrected)

fall_sd_mk_797_ad <- mk.test(fall_standard_dev_all_797_ad$sd_2)
print(fall_sd_mk_797_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_797_ad$sd_2
## z = 0, n = 31, p-value = 1
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
## -1.000000e+00  3.461667e+03 -2.150538e-03
fall_sd_sens_797_ad <- sens.slope(fall_standard_dev_all_797_ad$sd_2)
print(fall_sd_sens_797_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_797_ad$sd_2
## z = 0, n = 31, p-value = 1
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01815759  0.01862165
## sample estimates:
##   Sen's slope 
## -0.0003836623

Upper Rio Grande 839

Oyler -> Morrisey 5/26/2004

snotel_839 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "839")
#str(snotel_839) # check the date, usually a character.  

snotel_839$Date <- as.Date(snotel_839$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_839_clean <- snotel_839 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_839_clean <- snotel_839_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_839_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_839_clean <- snotel_839_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_839_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
#snotel_839_cull_count <- snotel_839_clean %>% 
#  filter(temperature_min > -40) %>% 
#  count(waterYear)

#snotel_839_cull_count

# filtering for too few observations in a year
snotel_839_cull_count_days <- snotel_839_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_839_cull_count_days
## # A tibble: 5 x 2
## # Groups:   waterYear [5]
##   waterYear     n
##       <dbl> <int>
## 1      1994   338
## 2      2004   330
## 3      2012   339
## 4      2014   313
## 5      2016   347

1994, 2004, 2012, 2014, 2016 need to be culled.

snotel_839_clean_culled <- snotel_839_clean %>% 
  filter(waterYear != "1994" & waterYear != "2004" & waterYear != "2012" & waterYear != "2014" & waterYear != "2016")# & waterYear != "2021" & waterYear != "2022") & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_839_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_839_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_839_xts <- xts(snotel_839_clean_culled$temperature_mean, order.by = snotel_839_clean_culled$Date)

dygraph(temp_839_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
#snotel_839_clean_culled <- snotel_839_clean_culled %>% 
#  filter(temperature_mean < 19.3)

temp_839_xts <- xts(snotel_839_clean_culled$temperature_mean, order.by = snotel_839_clean_culled$Date)

dygraph(temp_839_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Upper Rio Grande 839

Oyler -> Morrisey 5/26/2004

snotel_839_adjusted <- snotel_839_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2004-05-26", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

839 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_839 <- snotel_839_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_839 <- yearly_wy_aver_839 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(temperature_mean))

#average mean temperature by day for the period of record:

daily_wy_aver_839 <- daily_wy_aver_839 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_839$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_839 <-daily_wy_aver_839 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_839$date_temp <- signif(daily_wy_aver2_839$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_839, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

839 SD

standard_dev_839 <- daily_wy_aver_839 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_839 <- standard_dev_839 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_839 <- standard_dev_all_839 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_839 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.172439
1988 3.467186
1989 3.949359
1990 3.236041
1991 3.280121
1992 3.055381
1993 3.175525
1995 3.380351
1996 3.328827
1997 3.293297
1998 3.160550
1999 3.248483
2000 2.987335
2001 3.239614
2002 3.049272
2003 3.524510
2005 3.038954
2006 3.173996
2007 3.209333
2008 3.192942
2009 3.107169
2010 2.967969
2011 3.496251
2013 3.194751
2015 3.064511
2017 3.620606
2018 3.148185
2019 3.013658
2020 3.068378
2021 2.973718
2022 3.157851
ggplot(standard_dev_all_839, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 839 average temperatures for water years 2005-2021

MK & SS for 839 (non-corrected)

sd_mk_839 <- mk.test(standard_dev_all_839$sd_2)
print(sd_mk_839)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_839$sd_2
## z = -2.2775, n = 31, p-value = 0.02276
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -135.0000000 3461.6666667   -0.2903226
sd_sens_839 <- sens.slope(standard_dev_all_839$sd_2)
print(sd_sens_839)
## 
##  Sen's slope
## 
## data:  standard_dev_all_839$sd_2
## z = -2.2775, n = 31, p-value = 0.02276
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.014912747 -0.001241902
## sample estimates:
##  Sen's slope 
## -0.007580767

Corrected

839 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_839_ad <- snotel_839_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_839_ad <- yearly_wy_aver_839_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_839_ad <- daily_wy_aver_839_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_839_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_839_ad <-daily_wy_aver_839_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_839_ad$date_temp_ad <- signif(daily_wy_aver2_839_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_839_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

839 SS (corrected)

standard_dev_839_ad <- daily_wy_aver_839_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_839_ad <- standard_dev_839_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_839_ad <- standard_dev_all_839_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_839_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.990651
1988 3.301011
1989 3.795100
1990 3.097806
1991 3.128948
1992 2.894776
1993 2.996856
1995 3.226685
1996 3.176861
1997 3.143428
1998 2.949188
1999 3.159064
2000 2.847246
2001 3.031895
2002 2.806808
2003 3.298704
2005 3.039112
2006 3.119294
2007 3.202165
2008 3.221738
2009 3.029828
2010 3.041589
2011 3.503000
2013 3.249304
2015 2.980604
2017 3.547104
2018 3.049911
2019 3.018157
2020 3.112083
2021 2.998373
2022 3.112219
ggplot(standard_dev_all_839_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 839 average temperatures for water years 1986-2021

MK & SS 839 (corrected)

sd_mk_839_ad <- mk.test(standard_dev_all_839_ad$sd_2)
print(sd_mk_839_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_839_ad$sd_2
## z = 0, n = 31, p-value = 1
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
## -1.000000e+00  3.461667e+03 -2.150538e-03
sd_sens_839_ad <- sens.slope(standard_dev_all_839_ad$sd_2)
print(sd_sens_839_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_839_ad$sd_2
## z = 0, n = 31, p-value = 1
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.007276822  0.007562610
## sample estimates:
##   Sen's slope 
## -0.0001647931

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_839 <- standard_dev_839 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_839 <- summer_standard_dev_all_839 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_839 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.090734
1988 2.110820
1989 2.385818
1990 2.808392
1991 1.986606
1992 2.380196
1993 2.354813
1995 2.547384
1996 1.838435
1997 1.881548
1998 2.051467
1999 1.763688
2000 1.561982
2001 1.948128
2002 2.111087
2003 4.520215
2005 1.761650
2006 1.883576
2007 1.683518
2008 1.587542
2009 1.747644
2010 2.092758
2011 1.231928
2013 1.865244
2015 1.933036
2017 1.826728
2018 1.592085
2019 1.795570
2020 1.693440
2021 2.027776
2022 2.086123
ggplot(summer_standard_dev_all_839, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 839 average summer temperatures for water years 2005-2021

summer MK & SS for 839 (non-corrected)

summer_sd_mk_839 <- mk.test(summer_standard_dev_all_839$sd_2)
print(summer_sd_mk_839)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_839$sd_2
## z = -2.6514, n = 31, p-value = 0.008015
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -157.0000000 3461.6666667   -0.3376344
summer_sd_sens_839 <- sens.slope(summer_standard_dev_all_839$sd_2)
print(summer_sd_sens_839)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_839$sd_2
## z = -2.6514, n = 31, p-value = 0.008015
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.029070974 -0.003926793
## sample estimates:
## Sen's slope 
## -0.01695651

Winter

winter_standard_dev_all_839 <- standard_dev_839 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_839 <- winter_standard_dev_all_839 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_839 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.911970
1988 4.374947
1989 5.089096
1990 3.976710
1991 3.967133
1992 3.406159
1993 3.986282
1995 4.192436
1996 3.984824
1997 4.074971
1998 3.789487
1999 3.857520
2000 3.817341
2001 4.042296
2002 3.665736
2003 3.420296
2005 3.986819
2006 4.043254
2007 4.304220
2008 4.287536
2009 3.718727
2010 3.282843
2011 4.704305
2013 4.227055
2015 3.671276
2017 4.432109
2018 3.960874
2019 3.764227
2020 3.719449
2021 3.623705
2022 3.884286
ggplot(winter_standard_dev_all_839, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 839 average winter temperatures for water years 2005-2021

winter MK & SS for 839 (non-corrected)

winter_sd_mk_839 <- mk.test(winter_standard_dev_all_839$sd_2)
print(winter_sd_mk_839)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_839$sd_2
## z = -1.0198, n = 31, p-value = 0.3078
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -61.0000000 3461.6666667   -0.1311828
winter_sd_sens_839 <- sens.slope(winter_standard_dev_all_839$sd_2)
print(winter_sd_sens_839)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_839$sd_2
## z = -1.0198, n = 31, p-value = 0.3078
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.019239565  0.007722606
## sample estimates:
## Sen's slope 
## -0.00812185

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_839_ad <- standard_dev_839_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_839_ad <- summer_standard_dev_all_839_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_839_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 1.883589
1988 1.897589
1989 2.128833
1990 2.536773
1991 1.780624
1992 2.138273
1993 2.105235
1995 2.289283
1996 1.652554
1997 1.693399
1998 1.825807
1999 1.578950
2000 1.416725
2001 1.753670
2002 1.899574
2003 4.055283
2005 1.798203
2006 1.853797
2007 1.679893
2008 1.578264
2009 1.780771
2010 2.072620
2011 1.233842
2013 1.837293
2015 1.920974
2017 1.795284
2018 1.570099
2019 1.792445
2020 1.685874
2021 1.995831
2022 2.044230
ggplot(summer_standard_dev_all_839_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 839 average summer temperatures for water years 1986-2021

summer MK & SS 839 (corrected)

summer_sd_mk_839_ad <- mk.test(summer_standard_dev_all_839_ad$sd_2)
print(summer_sd_mk_839_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_839_ad$sd_2
## z = -1.2237, n = 31, p-value = 0.221
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -73.0000000 3461.6666667   -0.1569892
summer_sd_sens_839_ad <- sens.slope(summer_standard_dev_all_839_ad$sd_2)
print(summer_sd_sens_839_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_839_ad$sd_2
## z = -1.2237, n = 31, p-value = 0.221
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.018242325  0.003871489
## sample estimates:
##  Sen's slope 
## -0.005336647

Winter

winter_standard_dev_all_839_ad <- standard_dev_839_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_839_ad <- winter_standard_dev_all_839_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_839_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.818758
1988 4.293849
1989 5.016754
1990 3.878577
1991 3.900123
1992 3.326587
1993 3.887476
1995 4.069776
1996 3.850932
1997 3.958337
1998 3.676082
1999 3.739797
2000 3.683859
2001 3.949073
2002 3.531196
2003 3.317947
2005 3.966119
2006 4.035438
2007 4.311195
2008 4.303850
2009 3.711841
2010 3.290804
2011 4.703904
2013 4.235571
2015 3.675651
2017 4.438958
2018 3.945714
2019 3.750958
2020 3.726220
2021 3.619943
2022 3.880443
ggplot(winter_standard_dev_all_839_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 839 average winter temperatures for water years 1986-2021

winter MK & SS 839 (corrected)

winter_sd_mk_839_ad <- mk.test(winter_standard_dev_all_839_ad$sd_2)
print(winter_sd_mk_839_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_839_ad$sd_2
## z = -0.44191, n = 31, p-value = 0.6586
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -27.00000000 3461.66666667   -0.05806452
winter_sd_sens_839_ad <- sens.slope(winter_standard_dev_all_839_ad$sd_2)
print(winter_sd_sens_839_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_839_ad$sd_2
## z = -0.44191, n = 31, p-value = 0.6586
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01615067  0.01264233
## sample estimates:
##  Sen's slope 
## -0.002954691

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_839 <- standard_dev_839 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_839 <- spring_standard_dev_all_839 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_839 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.626298
1988 3.407189
1989 3.408621
1990 2.219835
1991 3.501501
1992 2.363717
1993 2.216458
1995 2.649673
1996 3.538408
1997 3.083488
1998 2.821002
1999 3.059886
2000 2.987341
2001 2.621679
2002 2.221703
2003 2.922517
2005 2.656072
2006 2.067920
2007 2.463629
2008 2.766260
2009 2.843581
2010 3.082323
2011 3.406280
2013 2.718464
2015 2.624236
2017 3.360029
2018 2.500823
2019 2.877293
2020 2.193117
2021 2.491317
2022 2.856698
ggplot(spring_standard_dev_all_839, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 839 average spring temperatures for water years 2005-2021

spring MK & SS for 839 (non-corrected)

spring_sd_mk_839 <- mk.test(spring_standard_dev_all_839$sd_2)
print(spring_sd_mk_839)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_839$sd_2
## z = -0.81583, n = 31, p-value = 0.4146
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -49.0000000 3461.6666667   -0.1053763
spring_sd_sens_839 <- sens.slope(spring_standard_dev_all_839$sd_2)
print(spring_sd_sens_839)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_839$sd_2
## z = -0.81583, n = 31, p-value = 0.4146
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02966356  0.01138147
## sample estimates:
##  Sen's slope 
## -0.007257933

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_839 <- standard_dev_839 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_839 <- fall_standard_dev_all_839 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_839 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.361414
1988 1.952956
1989 2.041600
1990 2.627830
1991 2.383232
1992 2.664568
1993 2.354534
1995 2.181192
1996 2.695028
1997 2.991863
1998 2.915280
1999 2.146994
2000 2.205449
2001 2.018193
2002 1.994576
2003 2.393620
2005 2.076840
2006 2.541823
2007 1.992608
2008 2.021324
2009 2.259019
2010 2.997629
2011 1.965758
2013 2.138031
2015 1.822187
2017 2.898991
2018 2.124289
2019 2.239727
2020 3.358541
2021 2.483554
2022 2.346427
ggplot(fall_standard_dev_all_839, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 839 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 839 (non-corrected)

fall_sd_mk_839 <- mk.test(fall_standard_dev_all_839$sd_2)
print(fall_sd_mk_839)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_839$sd_2
## z = -0.067986, n = 31, p-value = 0.9458
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##   -5.00000000 3461.66666667   -0.01075269
fall_sd_sens_839 <- sens.slope(fall_standard_dev_all_839$sd_2)
print(fall_sd_sens_839)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_839$sd_2
## z = -0.067986, n = 31, p-value = 0.9458
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01702274  0.01582389
## sample estimates:
##   Sen's slope 
## -0.0004995714

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_839_ad <- standard_dev_839_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_839_ad <- spring_standard_dev_all_839_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_839_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.445889
1988 3.130160
1989 3.137903
1990 2.073020
1991 3.270547
1992 2.192815
1993 2.014804
1995 2.471414
1996 3.211883
1997 2.833704
1998 2.567320
1999 2.821643
2000 2.700852
2001 2.378175
2002 2.045237
2003 2.662989
2005 2.692650
2006 2.068883
2007 2.438981
2008 2.760984
2009 2.873248
2010 3.096857
2011 3.377866
2013 2.715786
2015 2.554704
2017 3.321742
2018 2.486604
2019 2.806678
2020 2.212774
2021 2.463653
2022 2.860920
ggplot(spring_standard_dev_all_839_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 839 average spring temperatures for water years 1986-2021

spring MK & SS 839 (corrected)

spring_sd_mk_839_ad <- mk.test(spring_standard_dev_all_839_ad$sd_2)
print(spring_sd_mk_839_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_839_ad$sd_2
## z = 0.44191, n = 31, p-value = 0.6586
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 2.700000e+01 3.461667e+03 5.806452e-02
spring_sd_sens_839_ad <- sens.slope(spring_standard_dev_all_839_ad$sd_2)
print(spring_sd_sens_839_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_839_ad$sd_2
## z = 0.44191, n = 31, p-value = 0.6586
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01595289  0.02088826
## sample estimates:
## Sen's slope 
##  0.00453395

Fall

fall_standard_dev_all_839_ad <- standard_dev_839_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_839_ad <- fall_standard_dev_all_839_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_839_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.200935
1988 1.819476
1989 1.938321
1990 2.391431
1991 2.226915
1992 2.478622
1993 2.215469
1995 1.951252
1996 2.512784
1997 2.709922
1998 2.635661
1999 1.984007
2000 2.013821
2001 1.810044
2002 1.860102
2003 2.184630
2005 2.116387
2006 2.458807
2007 2.047274
2008 1.976853
2009 2.221550
2010 3.067953
2011 1.966365
2013 2.148651
2015 1.771202
2017 2.830983
2018 2.068560
2019 2.288754
2020 3.410530
2021 2.480534
2022 2.392226
ggplot(fall_standard_dev_all_839_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 839 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 839 (corrected)

fall_sd_mk_839_ad <- mk.test(fall_standard_dev_all_839_ad$sd_2)
print(fall_sd_mk_839_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_839_ad$sd_2
## z = 1.1558, n = 31, p-value = 0.2478
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   69.0000000 3461.6666667    0.1483871
fall_sd_sens_839_ad <- sens.slope(fall_standard_dev_all_839_ad$sd_2)
print(fall_sd_sens_839_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_839_ad$sd_2
## z = 1.1558, n = 31, p-value = 0.2478
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.005284237  0.023609228
## sample estimates:
## Sen's slope 
## 0.008188649

Upper San Juan 840

Morrisey 4/7/2004

snotel_840 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "840")
#str(snotel_840) # check the date, usually a character.  

snotel_840$Date <- as.Date(snotel_840$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_840_clean <- snotel_840 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_840_clean <- snotel_840_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_840_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_840_clean <- snotel_840_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_840_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
#snotel_840_cull_count <- snotel_840_clean %>% 
#  filter(temperature_min > -40) %>% 
#  count(waterYear)

#snotel_840_cull_count

# filtering for too few observations in a year
snotel_840_cull_count_days <- snotel_840_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_840_cull_count_days
## # A tibble: 11 x 2
## # Groups:   waterYear [11]
##    waterYear     n
##        <dbl> <int>
##  1      1980   310
##  2      1981   274
##  3      1982     1
##  4      1983   318
##  5      1984   322
##  6      1985   275
##  7      1993   349
##  8      1994   345
##  9      2005   309
## 10      2006   325
## 11      2013   314

1980, 1981, 1982, 1983, 1984, 1985, 1993, 1994, 2005, 2006, 2013 need to be culled.

snotel_840_clean_culled <- snotel_840_clean %>% 
  filter(waterYear >= "1986" & waterYear != "1993" & waterYear != "1994" & waterYear != "2005" & waterYear != "2006" & waterYear != "2013")# & waterYear != "2022") & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_840_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_840_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_840_xts <- xts(snotel_840_clean_culled$temperature_mean, order.by = snotel_840_clean_culled$Date)

dygraph(temp_840_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
#snotel_840_clean_culled <- snotel_840_clean_culled %>% 
#  filter(temperature_mean < 19.3)

temp_840_xts <- xts(snotel_840_clean_culled$temperature_mean, order.by = snotel_840_clean_culled$Date)

dygraph(temp_840_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Upper San Juan 840

Morrisey 4/7/2004

snotel_840_adjusted <- snotel_840_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2004-04-07", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

840 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_840 <- snotel_840_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_840 <- yearly_wy_aver_840 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(temperature_mean))

#average mean temperature by day for the period of record:

daily_wy_aver_840 <- daily_wy_aver_840 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_840$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_840 <-daily_wy_aver_840 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_840$date_temp <- signif(daily_wy_aver2_840$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_840, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

840 SD

standard_dev_840 <- daily_wy_aver_840 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_840 <- standard_dev_840 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_840 <- standard_dev_all_840 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_840 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 3.490810
1987 2.867215
1988 3.105881
1989 3.341846
1990 2.928320
1991 3.051047
1992 2.799049
1995 3.276923
1996 3.203071
1997 3.178575
1998 3.035432
1999 2.966454
2000 2.953989
2001 2.952691
2002 2.944303
2003 3.101590
2004 3.104638
2007 3.087797
2008 3.042248
2009 2.972902
2010 2.853308
2011 3.204896
2012 2.693361
2014 2.810099
2015 2.956094
2016 2.959836
2017 3.223074
2018 2.735811
2019 2.779483
2020 2.878255
2021 2.804333
2022 2.823037
ggplot(standard_dev_all_840, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 840 average temperatures for water years 2005-2021

MK & SS for 840 (non-corrected)

sd_mk_840 <- mk.test(standard_dev_all_840$sd_2)
print(sd_mk_840)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_840$sd_2
## z = -2.773, n = 32, p-value = 0.005554
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -172.0000000 3802.6666667   -0.3467742
sd_sens_840 <- sens.slope(standard_dev_all_840$sd_2)
print(sd_sens_840)
## 
##  Sen's slope
## 
## data:  standard_dev_all_840$sd_2
## z = -2.773, n = 32, p-value = 0.005554
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.017409590 -0.004560585
## sample estimates:
## Sen's slope 
## -0.01238477

Corrected

840 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_840_ad <- snotel_840_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_840_ad <- yearly_wy_aver_840_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_840_ad <- daily_wy_aver_840_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_840_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_840_ad <-daily_wy_aver_840_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_840_ad$date_temp_ad <- signif(daily_wy_aver2_840_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_840_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

840 SS (corrected)

standard_dev_840_ad <- daily_wy_aver_840_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_840_ad <- standard_dev_840_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_840_ad <- standard_dev_all_840_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_840_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 3.351961
1987 2.736414
1988 2.922657
1989 3.179476
1990 2.791784
1991 2.914867
1992 2.686113
1995 3.132509
1996 3.050809
1997 3.034998
1998 2.836761
1999 2.862476
2000 2.807359
2001 2.772948
2002 2.723250
2003 2.913991
2004 3.018237
2007 3.090784
2008 3.056774
2009 2.916602
2010 2.904860
2011 3.223008
2012 2.723485
2014 2.811756
2015 2.877204
2016 2.959139
2017 3.168916
2018 2.699434
2019 2.799804
2020 2.906446
2021 2.831101
2022 2.820088
ggplot(standard_dev_all_840_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 840 average temperatures for water years 1986-2021

MK & SS 840 (corrected)

sd_mk_840_ad <- mk.test(standard_dev_all_840_ad$sd_2)
print(sd_mk_840_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_840_ad$sd_2
## z = -0.92434, n = 32, p-value = 0.3553
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -58.0000000 3802.6666667   -0.1169355
sd_sens_840_ad <- sens.slope(standard_dev_all_840_ad$sd_2)
print(sd_sens_840_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_840_ad$sd_2
## z = -0.92434, n = 32, p-value = 0.3553
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.010736918  0.003420758
## sample estimates:
##  Sen's slope 
## -0.003310257

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_840 <- standard_dev_840 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_840 <- summer_standard_dev_all_840 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_840 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 1.857003
1987 1.704322
1988 1.869024
1989 2.033574
1990 2.129267
1991 1.708797
1992 1.878526
1995 2.673385
1996 1.527602
1997 1.654458
1998 1.995595
1999 1.785910
2000 1.412699
2001 1.704553
2002 1.718461
2003 3.064137
2004 1.763886
2007 1.642627
2008 1.644556
2009 1.708383
2010 1.644961
2011 1.188177
2012 1.395438
2014 1.445267
2015 1.678964
2016 1.983952
2017 1.594789
2018 1.484999
2019 1.712564
2020 1.628655
2021 1.964668
2022 1.875741
ggplot(summer_standard_dev_all_840, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 840 average summer temperatures for water years 2005-2021

summer MK & SS for 840 (non-corrected)

summer_sd_mk_840 <- mk.test(summer_standard_dev_all_840$sd_2)
print(summer_sd_mk_840)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_840$sd_2
## z = -1.7676, n = 32, p-value = 0.07713
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -110.0000000 3802.6666667   -0.2217742
summer_sd_sens_840 <- sens.slope(summer_standard_dev_all_840$sd_2)
print(summer_sd_sens_840)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_840$sd_2
## z = -1.7676, n = 32, p-value = 0.07713
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.016909684  0.000305243
## sample estimates:
##  Sen's slope 
## -0.007526772

Winter

winter_standard_dev_all_840 <- standard_dev_840 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_840 <- winter_standard_dev_all_840 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_840 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 4.486217
1987 3.682927
1988 3.690171
1989 4.135429
1990 3.664887
1991 3.768499
1992 3.098677
1995 3.838123
1996 3.874113
1997 3.749818
1998 3.481289
1999 3.281101
2000 3.806270
2001 3.544208
2002 3.511249
2003 3.335097
2004 3.893899
2007 4.051464
2008 3.923943
2009 3.643020
2010 3.143565
2011 4.142539
2012 3.239743
2014 3.168013
2015 3.533869
2016 3.702567
2017 3.793317
2018 3.440848
2019 3.261334
2020 3.141424
2021 3.493523
2022 3.332259
ggplot(winter_standard_dev_all_840, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 840 average winter temperatures for water years 2005-2021

winter MK & SS for 840 (non-corrected)

winter_sd_mk_840 <- mk.test(winter_standard_dev_all_840$sd_2)
print(winter_sd_mk_840)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_840$sd_2
## z = -2.1568, n = 32, p-value = 0.03102
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -134.0000000 3802.6666667   -0.2701613
winter_sd_sens_840 <- sens.slope(winter_standard_dev_all_840$sd_2)
print(winter_sd_sens_840)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_840$sd_2
## z = -2.1568, n = 32, p-value = 0.03102
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.028036345 -0.001457816
## sample estimates:
## Sen's slope 
## -0.01513226

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_840_ad <- standard_dev_840_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_840_ad <- summer_standard_dev_all_840_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_840_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 1.675739
1987 1.534522
1988 1.684597
1989 1.812961
1990 1.927409
1991 1.529377
1992 1.689138
1995 2.401424
1996 1.389335
1997 1.491063
1998 1.777699
1999 1.600481
2000 1.284330
2001 1.537331
2002 1.552902
2003 2.747813
2004 1.741690
2007 1.650189
2008 1.651944
2009 1.735888
2010 1.638826
2011 1.208555
2012 1.363643
2014 1.434378
2015 1.665577
2016 1.969351
2017 1.572235
2018 1.469823
2019 1.719831
2020 1.613733
2021 1.933846
2022 1.849753
ggplot(summer_standard_dev_all_840_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 840 average summer temperatures for water years 1986-2021

summer MK & SS 840 (corrected)

summer_sd_mk_840_ad <- mk.test(summer_standard_dev_all_840_ad$sd_2)
print(summer_sd_mk_840_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_840_ad$sd_2
## z = 0.081082, n = 32, p-value = 0.9354
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 6.000000e+00 3.802667e+03 1.209677e-02
summer_sd_sens_840_ad <- sens.slope(summer_standard_dev_all_840_ad$sd_2)
print(summer_sd_sens_840_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_840_ad$sd_2
## z = 0.081082, n = 32, p-value = 0.9354
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.008649059  0.008901758
## sample estimates:
##  Sen's slope 
## 0.0008652714

Winter

winter_standard_dev_all_840_ad <- standard_dev_840_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_840_ad <- winter_standard_dev_all_840_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_840_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 4.294879
1987 3.571075
1988 3.595836
1989 4.030283
1990 3.549006
1991 3.694568
1992 3.015309
1995 3.723291
1996 3.755009
1997 3.638049
1998 3.379858
1999 3.175066
2000 3.671078
2001 3.458171
2002 3.372510
2003 3.237958
2004 3.784003
2007 4.052655
2008 3.940185
2009 3.634763
2010 3.148749
2011 4.140815
2012 3.238175
2014 3.166373
2015 3.534742
2016 3.698931
2017 3.799183
2018 3.433872
2019 3.251678
2020 3.140855
2021 3.485535
2022 3.333112
ggplot(winter_standard_dev_all_840_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 840 average winter temperatures for water years 1986-2021

winter MK & SS 840 (corrected)

winter_sd_mk_840_ad <- mk.test(winter_standard_dev_all_840_ad$sd_2)
print(winter_sd_mk_840_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_840_ad$sd_2
## z = -1.5406, n = 32, p-value = 0.1234
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -96.0000000 3802.6666667   -0.1935484
winter_sd_sens_840_ad <- sens.slope(winter_standard_dev_all_840_ad$sd_2)
print(winter_sd_sens_840_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_840_ad$sd_2
## z = -1.5406, n = 32, p-value = 0.1234
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.023414834  0.003624228
## sample estimates:
## Sen's slope 
## -0.01068699

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_840 <- standard_dev_840 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_840 <- spring_standard_dev_all_840 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_840 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 2.781122
1987 2.551051
1988 3.286598
1989 3.161971
1990 2.202548
1991 3.300229
1992 2.360990
1995 2.781946
1996 3.408900
1997 3.091766
1998 2.838640
1999 3.378095
2000 2.868663
2001 3.013758
2002 2.558876
2003 3.241064
2004 2.370566
2007 2.685826
2008 2.753181
2009 2.644314
2010 3.261969
2011 3.259698
2012 2.879476
2014 3.385363
2015 2.655441
2016 2.727467
2017 3.490170
2018 2.474014
2019 3.181605
2020 2.372096
2021 2.417792
2022 2.772362
ggplot(spring_standard_dev_all_840, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 840 average spring temperatures for water years 2005-2021

spring MK & SS for 840 (non-corrected)

spring_sd_mk_840 <- mk.test(spring_standard_dev_all_840$sd_2)
print(spring_sd_mk_840)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_840$sd_2
## z = -0.40541, n = 32, p-value = 0.6852
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -26.00000000 3802.66666667   -0.05241935
spring_sd_sens_840 <- sens.slope(spring_standard_dev_all_840$sd_2)
print(spring_sd_sens_840)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_840$sd_2
## z = -0.40541, n = 32, p-value = 0.6852
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02061804  0.01180286
## sample estimates:
##  Sen's slope 
## -0.003091367

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_840 <- standard_dev_840 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_840 <- fall_standard_dev_all_840 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_840 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 2.472484
1987 1.990992
1988 2.026613
1989 2.102916
1990 2.549405
1991 2.146259
1992 3.017419
1995 2.534669
1996 2.765782
1997 3.346266
1998 3.024693
1999 2.153410
2000 2.269347
2001 1.992924
2002 2.117165
2003 2.200529
2004 2.723791
2007 2.051001
2008 2.384032
2009 2.351934
2010 3.074237
2011 2.255784
2012 2.151403
2014 2.772971
2015 1.913917
2016 2.044707
2017 2.717003
2018 2.084809
2019 2.146388
2020 3.554620
2021 2.115050
2022 2.557280
ggplot(fall_standard_dev_all_840, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 840 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 840 (non-corrected)

fall_sd_mk_840 <- mk.test(fall_standard_dev_all_840$sd_2)
print(fall_sd_mk_840)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_840$sd_2
## z = 0.17838, n = 32, p-value = 0.8584
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 1.200000e+01 3.802667e+03 2.419355e-02
fall_sd_sens_840 <- sens.slope(fall_standard_dev_all_840$sd_2)
print(fall_sd_sens_840)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_840$sd_2
## z = 0.17838, n = 32, p-value = 0.8584
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01502079  0.01496691
## sample estimates:
##  Sen's slope 
## 0.0006329894

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_840_ad <- standard_dev_840_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_840_ad <- spring_standard_dev_all_840_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_840_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 2.577999
1987 2.381879
1988 3.054895
1989 2.919447
1990 2.065192
1991 3.071811
1992 2.213595
1995 2.606594
1996 3.124168
1997 2.878948
1998 2.614053
1999 3.154071
2000 2.623168
2001 2.777428
2002 2.360162
2003 2.996353
2004 2.378097
2007 2.669355
2008 2.753446
2009 2.683159
2010 3.276943
2011 3.243908
2012 2.870883
2014 3.390018
2015 2.608117
2016 2.712946
2017 3.472024
2018 2.477294
2019 3.132923
2020 2.390555
2021 2.403938
2022 2.782694
ggplot(spring_standard_dev_all_840_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 840 average spring temperatures for water years 1986-2021

spring MK & SS 840 (corrected)

spring_sd_mk_840_ad <- mk.test(spring_standard_dev_all_840_ad$sd_2)
print(spring_sd_mk_840_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_840_ad$sd_2
## z = 0.9892, n = 32, p-value = 0.3226
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##        S     varS      tau 
##   62.000 3802.667    0.125
spring_sd_sens_840_ad <- sens.slope(spring_standard_dev_all_840_ad$sd_2)
print(spring_sd_sens_840_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_840_ad$sd_2
## z = 0.9892, n = 32, p-value = 0.3226
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01050571  0.01956751
## sample estimates:
## Sen's slope 
## 0.006597983

Fall

fall_standard_dev_all_840_ad <- standard_dev_840_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_840_ad <- fall_standard_dev_all_840_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_840_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 2.322647
1987 1.865978
1988 1.886048
1989 1.977522
1990 2.303617
1991 2.010537
1992 2.820816
1995 2.290233
1996 2.576685
1997 3.055640
1998 2.762507
1999 2.025373
2000 2.087680
2001 1.810504
2002 1.969110
2003 2.016423
2004 2.870227
2007 2.099688
2008 2.314141
2009 2.315162
2010 3.140046
2011 2.239567
2012 2.183061
2014 2.829849
2015 1.857964
2016 1.991912
2017 2.656824
2018 2.059096
2019 2.185714
2020 3.610696
2021 2.121692
2022 2.610451
ggplot(fall_standard_dev_all_840_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 840 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 840 (corrected)

fall_sd_mk_840_ad <- mk.test(fall_standard_dev_all_840_ad$sd_2)
print(fall_sd_mk_840_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_840_ad$sd_2
## z = 1.2162, n = 32, p-value = 0.2239
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   76.0000000 3802.6666667    0.1532258
fall_sd_sens_840_ad <- sens.slope(fall_standard_dev_all_840_ad$sd_2)
print(fall_sd_sens_840_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_840_ad$sd_2
## z = 1.2162, n = 32, p-value = 0.2239
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.005693258  0.023805517
## sample estimates:
## Sen's slope 
## 0.007644862

Vallecito 843

Morrisey 7/22/2005

snotel_843 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "843")
#str(snotel_843) # check the date, usually a character.  

snotel_843$Date <- as.Date(snotel_843$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_843_clean <- snotel_843 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_843_clean <- snotel_843_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_843_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_843_clean <- snotel_843_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_843_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
#snotel_843_cull_count <- snotel_843_clean %>% 
#  filter(temperature_min > -40) %>% 
#  count(waterYear)

#snotel_843_cull_count

# filtering for too few observations in a year
snotel_843_cull_count_days <- snotel_843_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_843_cull_count_days
## # A tibble: 2 x 2
## # Groups:   waterYear [2]
##   waterYear     n
##       <dbl> <int>
## 1      1994   339
## 2      2003   313

1994 & 2003 need to be culled.

snotel_843_clean_culled <- snotel_843_clean %>% 
  filter(waterYear != "1994" & waterYear != "2003")# & waterYear != "1994" & waterYear != "2005" & waterYear != "2006" & waterYear != "2013")# & waterYear != "2022") & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_843_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_843_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_843_xts <- xts(snotel_843_clean_culled$temperature_mean, order.by = snotel_843_clean_culled$Date)

dygraph(temp_843_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
#snotel_843_clean_culled <- snotel_843_clean_culled %>% 
#  filter(temperature_mean < 19.3)

temp_843_xts <- xts(snotel_843_clean_culled$temperature_mean, order.by = snotel_843_clean_culled$Date)

dygraph(temp_843_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Vallecito 843

Morrisey 7/22/2005

snotel_843_adjusted <- snotel_843_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2005-07-22", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

843 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_843 <- snotel_843_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_843 <- yearly_wy_aver_843 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(temperature_mean))

#average mean temperature by day for the period of record:

daily_wy_aver_843 <- daily_wy_aver_843 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_843$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_843 <-daily_wy_aver_843 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_843$date_temp <- signif(daily_wy_aver2_843$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_843, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

843 SD

standard_dev_843 <- daily_wy_aver_843 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_843 <- standard_dev_843 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_843 <- standard_dev_all_843 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_843 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.583047
1988 3.740718
1989 4.222244
1990 3.735270
1991 3.855525
1992 3.625778
1993 3.483027
1995 4.009113
1996 4.047937
1997 3.828791
1998 3.513884
1999 3.625041
2000 3.674697
2001 3.805620
2002 3.623254
2004 4.059271
2005 3.542988
2006 3.541605
2007 3.611133
2008 3.452804
2009 3.639819
2010 3.448661
2011 3.702019
2012 3.435358
2013 3.759390
2014 3.513305
2015 3.568125
2016 3.546369
2017 3.489161
2018 3.180529
2019 3.357583
2020 3.368005
2021 3.527359
2022 3.609449
ggplot(standard_dev_all_843, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 843 average temperatures for water years 2005-2021

MK & SS for 843 (non-corrected)

sd_mk_843 <- mk.test(standard_dev_all_843$sd_2)
print(sd_mk_843)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_843$sd_2
## z = -3.4986, n = 34, p-value = 0.0004678
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -237.0000000 4550.3333333   -0.4224599
sd_sens_843 <- sens.slope(standard_dev_all_843$sd_2)
print(sd_sens_843)
## 
##  Sen's slope
## 
## data:  standard_dev_all_843$sd_2
## z = -3.4986, n = 34, p-value = 0.0004678
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.018056288 -0.005226834
## sample estimates:
## Sen's slope 
## -0.01072779

Corrected

843 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_843_ad <- snotel_843_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_843_ad <- yearly_wy_aver_843_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_843_ad <- daily_wy_aver_843_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_843_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_843_ad <-daily_wy_aver_843_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_843_ad$date_temp_ad <- signif(daily_wy_aver2_843_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_843_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

843 SS (corrected)

standard_dev_843_ad <- daily_wy_aver_843_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_843_ad <- standard_dev_843_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_843_ad <- standard_dev_all_843_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_843_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.364589
1988 3.504931
1989 3.977830
1990 3.505807
1991 3.650638
1992 3.435245
1993 3.262936
1995 3.762779
1996 3.790557
1997 3.577263
1998 3.245963
1999 3.469888
2000 3.409742
2001 3.535916
2002 3.339515
2004 3.929879
2005 3.303655
2006 3.508160
2007 3.612917
2008 3.494021
2009 3.610218
2010 3.475447
2011 3.724080
2012 3.450931
2013 3.783383
2014 3.498225
2015 3.501173
2016 3.541719
2017 3.476373
2018 3.158145
2019 3.391159
2020 3.406133
2021 3.560302
2022 3.583121
ggplot(standard_dev_all_843_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 843 average temperatures for water years 1986-2021

MK & SS 843 (corrected)

sd_mk_843_ad <- mk.test(standard_dev_all_843_ad$sd_2)
print(sd_mk_843_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_843_ad$sd_2
## z = -0.35579, n = 34, p-value = 0.722
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -25.00000000 4550.33333333   -0.04456328
sd_sens_843_ad <- sens.slope(standard_dev_all_843_ad$sd_2)
print(sd_sens_843_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_843_ad$sd_2
## z = -0.35579, n = 34, p-value = 0.722
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.008498459  0.005145198
## sample estimates:
##  Sen's slope 
## -0.001119669

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_843 <- standard_dev_843 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_843 <- summer_standard_dev_all_843 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_843 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.205277
1988 2.228607
1989 2.687863
1990 2.949868
1991 2.244793
1992 2.560382
1993 2.849142
1995 3.334198
1996 2.620303
1997 2.301357
1998 2.801740
1999 2.328103
2000 2.062198
2001 2.311835
2002 2.273785
2004 2.891880
2005 2.434411
2006 2.112479
2007 2.164951
2008 2.101163
2009 2.484773
2010 2.622292
2011 1.658866
2012 1.738203
2013 2.247254
2014 1.871827
2015 2.277638
2016 2.369208
2017 1.924208
2018 1.986767
2019 2.322507
2020 2.314435
2021 2.465557
2022 2.462845
ggplot(summer_standard_dev_all_843, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 843 average summer temperatures for water years 2005-2021

summer MK & SS for 843 (non-corrected)

summer_sd_mk_843 <- mk.test(summer_standard_dev_all_843$sd_2)
print(summer_sd_mk_843)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_843$sd_2
## z = -1.5714, n = 34, p-value = 0.1161
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -107.0000000 4550.3333333   -0.1907308
summer_sd_sens_843 <- sens.slope(summer_standard_dev_all_843$sd_2)
print(summer_sd_sens_843)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_843$sd_2
## z = -1.5714, n = 34, p-value = 0.1161
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.024074329  0.002391146
## sample estimates:
## Sen's slope 
## -0.01185058

Winter

winter_standard_dev_all_843 <- standard_dev_843 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_843 <- winter_standard_dev_all_843 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_843 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 4.449370
1988 4.391336
1989 5.198729
1990 4.561562
1991 4.754523
1992 3.807671
1993 4.020024
1995 4.559403
1996 4.723301
1997 4.387929
1998 3.854303
1999 4.030016
2000 4.351231
2001 4.387933
2002 4.269043
2004 3.086736
2005 4.190032
2006 4.290208
2007 4.464226
2008 4.172698
2009 4.325908
2010 3.583347
2011 4.618378
2012 4.197527
2013 4.853228
2014 3.998375
2015 4.014618
2016 4.412811
2017 4.107253
2018 3.990982
2019 3.736651
2020 3.575844
2021 4.093456
2022 4.260080
ggplot(winter_standard_dev_all_843, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 843 average winter temperatures for water years 2005-2021

winter MK & SS for 843 (non-corrected)

winter_sd_mk_843 <- mk.test(winter_standard_dev_all_843$sd_2)
print(winter_sd_mk_843)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_843$sd_2
## z = -2.4609, n = 34, p-value = 0.01386
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -167.0000000 4550.3333333   -0.2976827
winter_sd_sens_843 <- sens.slope(winter_standard_dev_all_843$sd_2)
print(winter_sd_sens_843)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_843$sd_2
## z = -2.4609, n = 34, p-value = 0.01386
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.026969611 -0.003443574
## sample estimates:
## Sen's slope 
## -0.01524866

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_843_ad <- standard_dev_843_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_843_ad <- summer_standard_dev_all_843_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_843_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 1.986885
1988 1.998525
1989 2.396504
1990 2.647732
1991 2.013027
1992 2.291291
1993 2.551338
1995 2.993391
1996 2.355530
1997 2.061566
1998 2.500348
1999 2.097005
2000 1.860692
2001 2.081299
2002 2.047391
2004 2.616368
2005 2.202021
2006 2.081871
2007 2.169154
2008 2.109828
2009 2.517674
2010 2.611985
2011 1.661049
2012 1.712860
2013 2.210358
2014 1.867971
2015 2.268740
2016 2.358145
2017 1.909968
2018 1.972884
2019 2.318635
2020 2.314168
2021 2.439938
2022 2.440911
ggplot(summer_standard_dev_all_843_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 843 average summer temperatures for water years 1986-2021

summer MK & SS 843 (corrected)

summer_sd_mk_843_ad <- mk.test(summer_standard_dev_all_843_ad$sd_2)
print(summer_sd_mk_843_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_843_ad$sd_2
## z = 0.059298, n = 34, p-value = 0.9527
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 5.000000e+00 4.550333e+03 8.912656e-03
summer_sd_sens_843_ad <- sens.slope(summer_standard_dev_all_843_ad$sd_2)
print(summer_sd_sens_843_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_843_ad$sd_2
## z = 0.059298, n = 34, p-value = 0.9527
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01253028  0.01144903
## sample estimates:
##  Sen's slope 
## 0.0005598741

Winter

winter_standard_dev_all_843_ad <- standard_dev_843_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_843_ad <- winter_standard_dev_all_843_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_843_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 4.258199
1988 4.212639
1989 5.005839
1990 4.356612
1991 4.573056
1992 3.651803
1993 3.878721
1995 4.364636
1996 4.508766
1997 4.169269
1998 3.685385
1999 3.845775
2000 4.113450
2001 4.219859
2002 4.074472
2004 2.870779
2005 3.995468
2006 4.279636
2007 4.469889
2008 4.192346
2009 4.322833
2010 3.587871
2011 4.610842
2012 4.189264
2013 4.855185
2014 3.992882
2015 4.012920
2016 4.404850
2017 4.121308
2018 3.984009
2019 3.725429
2020 3.577750
2021 4.086414
2022 4.259791
ggplot(winter_standard_dev_all_843_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 843 average winter temperatures for water years 1986-2021

winter MK & SS 843 (corrected)

winter_sd_mk_843_ad <- mk.test(winter_standard_dev_all_843_ad$sd_2)
print(winter_sd_mk_843_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_843_ad$sd_2
## z = -1.1563, n = 34, p-value = 0.2476
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##          S       varS        tau 
##  -79.00000 4550.33333   -0.14082
winter_sd_sens_843_ad <- sens.slope(winter_standard_dev_all_843_ad$sd_2)
print(winter_sd_sens_843_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_843_ad$sd_2
## z = -1.1563, n = 34, p-value = 0.2476
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.019288506  0.006716428
## sample estimates:
##  Sen's slope 
## -0.007023414

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_843 <- standard_dev_843 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_843 <- spring_standard_dev_all_843 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_843 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.303749
1988 4.325303
1989 4.113237
1990 2.736483
1991 4.005813
1992 3.213957
1993 3.058803
1995 3.476835
1996 3.893232
1997 3.925657
1998 3.613386
1999 3.783210
2000 3.824562
2001 4.047925
2002 3.191030
2004 2.477079
2005 3.747893
2006 2.927082
2007 3.553720
2008 3.319795
2009 3.362087
2010 3.665573
2011 3.763672
2012 3.386057
2013 3.168303
2014 3.991586
2015 3.410881
2016 3.222492
2017 3.899795
2018 2.924367
2019 3.779473
2020 2.852679
2021 3.141408
2022 3.264362
ggplot(spring_standard_dev_all_843, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 843 average spring temperatures for water years 2005-2021

spring MK & SS for 843 (non-corrected)

spring_sd_mk_843 <- mk.test(spring_standard_dev_all_843$sd_2)
print(spring_sd_mk_843)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_843$sd_2
## z = -1.601, n = 34, p-value = 0.1094
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -109.0000000 4550.3333333   -0.1942959
spring_sd_sens_843 <- sens.slope(spring_standard_dev_all_843$sd_2)
print(spring_sd_sens_843)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_843$sd_2
## z = -1.601, n = 34, p-value = 0.1094
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.031800441  0.004120431
## sample estimates:
## Sen's slope 
## -0.01390485

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_843 <- standard_dev_843 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_843 <- fall_standard_dev_all_843 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_843 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.951608
1988 2.943422
1989 2.654833
1990 3.452439
1991 3.009665
1992 4.263227
1993 2.953677
1995 3.501217
1996 3.851498
1997 4.135259
1998 3.096616
1999 2.822677
2000 3.377532
2001 3.177610
2002 2.856553
2004 4.831826
2005 2.861862
2006 3.033386
2007 2.689900
2008 3.083347
2009 3.282999
2010 3.942857
2011 2.862773
2012 3.191057
2013 2.907542
2014 3.462981
2015 2.660434
2016 2.707160
2017 3.134239
2018 2.482810
2019 3.034556
2020 4.284172
2021 3.189816
2022 3.451479
ggplot(fall_standard_dev_all_843, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 843 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 843 (non-corrected)

fall_sd_mk_843 <- mk.test(fall_standard_dev_all_843$sd_2)
print(fall_sd_mk_843)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_843$sd_2
## z = -0.059298, n = 34, p-value = 0.9527
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
## -5.000000e+00  4.550333e+03 -8.912656e-03
fall_sd_sens_843 <- sens.slope(fall_standard_dev_all_843$sd_2)
print(fall_sd_sens_843)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_843$sd_2
## z = -0.059298, n = 34, p-value = 0.9527
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01859493  0.01396353
## sample estimates:
##  Sen's slope 
## -0.001437698

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_843_ad <- standard_dev_843_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_843_ad <- spring_standard_dev_all_843_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_843_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.076726
1988 3.999134
1989 3.796631
1990 2.541886
1991 3.739809
1992 2.976074
1993 2.796735
1995 3.260612
1996 3.554106
1997 3.611987
1998 3.324738
1999 3.518819
2000 3.477839
2001 3.714627
2002 2.915419
2004 2.291633
2005 3.430743
2006 2.936105
2007 3.550649
2008 3.328000
2009 3.394834
2010 3.675892
2011 3.739920
2012 3.373159
2013 3.182131
2014 3.990431
2015 3.357930
2016 3.200627
2017 3.872993
2018 2.941276
2019 3.721915
2020 2.877007
2021 3.120607
2022 3.272524
ggplot(spring_standard_dev_all_843_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 843 average spring temperatures for water years 1986-2021

spring MK & SS 843 (corrected)

spring_sd_mk_843_ad <- mk.test(spring_standard_dev_all_843_ad$sd_2)
print(spring_sd_mk_843_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_843_ad$sd_2
## z = -0.29649, n = 34, p-value = 0.7669
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -21.00000000 4550.33333333   -0.03743316
spring_sd_sens_843_ad <- sens.slope(spring_standard_dev_all_843_ad$sd_2)
print(spring_sd_sens_843_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_843_ad$sd_2
## z = -0.29649, n = 34, p-value = 0.7669
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01848083  0.01483542
## sample estimates:
##  Sen's slope 
## -0.002999273

Fall

fall_standard_dev_all_843_ad <- standard_dev_843_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_843_ad <- fall_standard_dev_all_843_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_843_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.722495
1988 2.721177
1989 2.474656
1990 3.104751
1991 2.802936
1992 3.964129
1993 2.741983
1995 3.179892
1996 3.574972
1997 3.770797
1998 2.807600
1999 2.601923
2000 3.111342
2001 2.840177
2002 2.635289
2004 4.484040
2005 2.476246
2006 2.981445
2007 2.722228
2008 3.043323
2009 3.243276
2010 4.002783
2011 2.864539
2012 3.208098
2013 2.893134
2014 3.506913
2015 2.618886
2016 2.686096
2017 3.089652
2018 2.459225
2019 3.074186
2020 4.329904
2021 3.188840
2022 3.482895
ggplot(fall_standard_dev_all_843_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 843 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 843 (corrected)

fall_sd_mk_843_ad <- mk.test(fall_standard_dev_all_843_ad$sd_2)
print(fall_sd_mk_843_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_843_ad$sd_2
## z = 1.1267, n = 34, p-value = 0.2599
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   77.0000000 4550.3333333    0.1372549
fall_sd_sens_843_ad <- sens.slope(fall_standard_dev_all_843_ad$sd_2)
print(fall_sd_sens_843_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_843_ad$sd_2
## z = 1.1267, n = 34, p-value = 0.2599
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.006606768  0.024797042
## sample estimates:
## Sen's slope 
## 0.009602554

Wolf Creek Summit 874

Morrisey 7/12/2004

snotel_874 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "874")
#str(snotel_874) # check the date, usually a character.  

snotel_874$Date <- as.Date(snotel_874$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_874_clean <- snotel_874 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_874_clean <- snotel_874_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_874_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_874_clean <- snotel_874_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_874_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
#snotel_874_cull_count <- snotel_874_clean %>% 
#  filter(temperature_min > -40) %>% 
#  count(waterYear)

#snotel_874_cull_count

# filtering for too few observations in a year
snotel_874_cull_count_days <- snotel_874_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_874_cull_count_days
## # A tibble: 11 x 2
## # Groups:   waterYear [11]
##    waterYear     n
##        <dbl> <int>
##  1      1990   295
##  2      1994   313
##  3      2003   311
##  4      2006   340
##  5      2007   340
##  6      2008   315
##  7      2009   320
##  8      2010   303
##  9      2013   304
## 10      2016   338
## 11      2017   314

1990, 1994, 2003, 2006, 2007, 2008, 2009, 2010, 2013, 2016, 2017 need to be culled.

snotel_874_clean_culled <- snotel_874_clean %>% 
  filter(waterYear != "1990" & waterYear != "1994" & waterYear != "2003" & waterYear != "2006" & waterYear != "2007" & waterYear != "2008" & waterYear != "2009" & waterYear != "2010" & waterYear != "2013" & waterYear != "2016" & waterYear != "2017") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_874_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_874_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_874_xts <- xts(snotel_874_clean_culled$temperature_mean, order.by = snotel_874_clean_culled$Date)

dygraph(temp_874_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
#snotel_874_clean_culled <- snotel_874_clean_culled %>% 
#  filter(temperature_mean < 19.3)

temp_874_xts <- xts(snotel_874_clean_culled$temperature_mean, order.by = snotel_874_clean_culled$Date)

dygraph(temp_874_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Wolf Creek Summit 874

Morrisey 7/12/2004

snotel_874_adjusted <- snotel_874_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2004-07-12", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

874 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_874 <- snotel_874_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_874 <- yearly_wy_aver_874 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(temperature_mean))

#average mean temperature by day for the period of record:

daily_wy_aver_874 <- daily_wy_aver_874 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_874$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_874 <-daily_wy_aver_874 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_874$date_temp <- signif(daily_wy_aver2_874$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_874, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

874 SD

standard_dev_874 <- daily_wy_aver_874 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_874 <- standard_dev_874 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_874 <- standard_dev_all_874 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_874 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.249764
1988 3.546899
1989 3.717493
1991 3.455619
1992 3.173875
1993 3.040374
1995 3.610732
1996 3.649458
1997 3.563022
1998 3.279914
1999 3.372722
2000 3.536572
2001 3.388049
2002 3.535663
2004 3.689674
2005 3.248969
2011 3.604738
2012 3.234986
2014 3.275495
2015 3.434284
2018 3.057468
2019 3.138228
2020 3.222073
2021 3.438392
2022 3.475705
ggplot(standard_dev_all_874, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 874 average temperatures for water years 2005-2021

MK & SS for 874 (non-corrected)

sd_mk_874 <- mk.test(standard_dev_all_874$sd_2)
print(sd_mk_874)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_874$sd_2
## z = -1.2378, n = 25, p-value = 0.2158
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##        S     varS      tau 
##  -54.000 1833.333   -0.180
sd_sens_874 <- sens.slope(standard_dev_all_874$sd_2)
print(sd_sens_874)
## 
##  Sen's slope
## 
## data:  standard_dev_all_874$sd_2
## z = -1.2378, n = 25, p-value = 0.2158
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.018972096  0.006826747
## sample estimates:
##  Sen's slope 
## -0.007133742

Corrected

874 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_874_ad <- snotel_874_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_874_ad <- yearly_wy_aver_874_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_874_ad <- daily_wy_aver_874_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_874_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_874_ad <-daily_wy_aver_874_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_874_ad$date_temp_ad <- signif(daily_wy_aver2_874_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_874_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

874 SS (corrected)

standard_dev_874_ad <- daily_wy_aver_874_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_874_ad <- standard_dev_874_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_874_ad <- standard_dev_all_874_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_874_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.089894
1988 3.360429
1989 3.531114
1991 3.302963
1992 3.022629
1993 2.872152
1995 3.429123
1996 3.451678
1997 3.384913
1998 3.064271
1999 3.240169
2000 3.323625
2001 3.183386
2002 3.285319
2004 3.571202
2005 3.242610
2011 3.629940
2012 3.246203
2014 3.255582
2015 3.355129
2018 3.018807
2019 3.162718
2020 3.243268
2021 3.457971
2022 3.421988
ggplot(standard_dev_all_874_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 874 average temperatures for water years 1986-2021

MK & SS 874 (corrected)

sd_mk_874_ad <- mk.test(standard_dev_all_874_ad$sd_2)
print(sd_mk_874_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_874_ad$sd_2
## z = 0.35032, n = 25, p-value = 0.7261
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 1.600000e+01 1.833333e+03 5.333333e-02
sd_sens_874_ad <- sens.slope(standard_dev_all_874_ad$sd_2)
print(sd_sens_874_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_874_ad$sd_2
## z = 0.35032, n = 25, p-value = 0.7261
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.009885515  0.015208125
## sample estimates:
## Sen's slope 
## 0.002121874

Figure captions are not correct.

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_874 <- standard_dev_874 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_874 <- summer_standard_dev_all_874 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_874 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 1.902572
1988 2.174371
1989 2.387159
1991 2.123524
1992 2.343703
1993 2.447675
1995 3.105321
1996 2.134161
1997 2.143653
1998 2.514563
1999 2.036019
2000 1.839238
2001 2.154508
2002 2.211496
2004 2.327431
2005 2.180010
2011 1.557956
2012 1.812555
2014 1.778875
2015 2.257052
2018 2.007551
2019 2.237773
2020 2.090618
2021 2.606785
2022 2.504544
ggplot(summer_standard_dev_all_874, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 874 average summer temperatures for water years 2005-2021

summer MK & SS for 874 (non-corrected)

summer_sd_mk_874 <- mk.test(summer_standard_dev_all_874$sd_2)
print(summer_sd_mk_874)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_874$sd_2
## z = -0.11677, n = 25, p-value = 0.907
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##        S     varS      tau 
##   -6.000 1833.333   -0.020
summer_sd_sens_874 <- sens.slope(summer_standard_dev_all_874$sd_2)
print(summer_sd_sens_874)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_874$sd_2
## z = -0.11677, n = 25, p-value = 0.907
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02108931  0.01435537
## sample estimates:
## Sen's slope 
## -0.00176879

Winter

winter_standard_dev_all_874 <- standard_dev_874 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_874 <- winter_standard_dev_all_874 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_874 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 4.050932
1988 4.108105
1989 4.504123
1991 4.248526
1992 3.210433
1993 3.382916
1995 3.993016
1996 4.200196
1997 4.081614
1998 3.560611
1999 3.599147
2000 4.181729
2001 3.961143
2002 4.117361
2004 4.394787
2005 3.885696
2011 4.504096
2012 3.894777
2014 3.611678
2015 3.845998
2018 3.718050
2019 3.500018
2020 3.452893
2021 4.016365
2022 4.046645
ggplot(winter_standard_dev_all_874, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 874 average winter temperatures for water years 2005-2021

winter MK & SS for 874 (non-corrected)

winter_sd_mk_874 <- mk.test(winter_standard_dev_all_874$sd_2)
print(winter_sd_mk_874)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_874$sd_2
## z = -1.1444, n = 25, p-value = 0.2525
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -50.0000000 1833.3333333   -0.1666667
winter_sd_sens_874 <- sens.slope(winter_standard_dev_all_874$sd_2)
print(winter_sd_sens_874)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_874$sd_2
## z = -1.1444, n = 25, p-value = 0.2525
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03120449  0.01346998
## sample estimates:
## Sen's slope 
## -0.01058854

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_874_ad <- standard_dev_874_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_874_ad <- summer_standard_dev_all_874_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_874_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 1.709835
1988 1.960481
1989 2.128424
1991 1.913132
1992 2.110901
1993 2.198325
1995 2.797866
1996 1.923808
1997 1.940187
1998 2.252360
1999 1.837836
2000 1.657742
2001 1.948095
2002 1.989086
2004 2.202606
2005 2.227966
2011 1.562906
2012 1.772327
2014 1.763057
2015 2.246289
2018 1.978350
2019 2.234473
2020 2.087715
2021 2.571035
2022 2.463827
ggplot(summer_standard_dev_all_874_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 874 average summer temperatures for water years 1986-2021

summer MK & SS 874 (corrected)

summer_sd_mk_874_ad <- mk.test(summer_standard_dev_all_874_ad$sd_2)
print(summer_sd_mk_874_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_874_ad$sd_2
## z = 1.3779, n = 25, p-value = 0.1682
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##        S     varS      tau 
##   60.000 1833.333    0.200
summer_sd_sens_874_ad <- sens.slope(summer_standard_dev_all_874_ad$sd_2)
print(summer_sd_sens_874_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_874_ad$sd_2
## z = 1.3779, n = 25, p-value = 0.1682
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.008284444  0.026223556
## sample estimates:
## Sen's slope 
##  0.00917953

Winter

winter_standard_dev_all_874_ad <- standard_dev_874_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_874_ad <- winter_standard_dev_all_874_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_874_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.926122
1988 3.999947
1989 4.379422
1991 4.135939
1992 3.107630
1993 3.289801
1995 3.872299
1996 4.060143
1997 3.946298
1998 3.446697
1999 3.468872
2000 3.994590
2001 3.851879
2002 3.971746
2004 4.251807
2005 3.870972
2011 4.502991
2012 3.893980
2014 3.607944
2015 3.848273
2018 3.710190
2019 3.488374
2020 3.452712
2021 4.010320
2022 4.046071
ggplot(winter_standard_dev_all_874_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 874 average winter temperatures for water years 1986-2021

winter MK & SS 874 (corrected)

winter_sd_mk_874_ad <- mk.test(winter_standard_dev_all_874_ad$sd_2)
print(winter_sd_mk_874_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_874_ad$sd_2
## z = -0.44374, n = 25, p-value = 0.6572
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -20.00000000 1833.33333333   -0.06666667
winter_sd_sens_874_ad <- sens.slope(winter_standard_dev_all_874_ad$sd_2)
print(winter_sd_sens_874_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_874_ad$sd_2
## z = -0.44374, n = 25, p-value = 0.6572
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02208059  0.01738402
## sample estimates:
##  Sen's slope 
## -0.003540021

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_874 <- standard_dev_874 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_874 <- spring_standard_dev_all_874 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_874 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.204083
1988 4.113435
1989 3.606146
1991 3.515190
1992 3.144794
1993 2.794429
1995 3.123401
1996 3.763876
1997 3.492839
1998 3.410409
1999 3.719731
2000 3.816162
2001 3.610228
2002 3.027440
2004 3.197480
2005 3.352513
2011 3.741368
2012 3.246644
2014 3.970760
2015 3.205603
2018 2.799449
2019 3.677889
2020 2.622088
2021 3.105498
2022 3.091546
ggplot(spring_standard_dev_all_874, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 874 average spring temperatures for water years 2005-2021

spring MK & SS for 874 (non-corrected)

spring_sd_mk_874 <- mk.test(spring_standard_dev_all_874$sd_2)
print(spring_sd_mk_874)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_874$sd_2
## z = -1.3312, n = 25, p-value = 0.1831
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -58.0000000 1833.3333333   -0.1933333
spring_sd_sens_874 <- sens.slope(spring_standard_dev_all_874$sd_2)
print(spring_sd_sens_874)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_874$sd_2
## z = -1.3312, n = 25, p-value = 0.1831
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.041148642  0.007834622
## sample estimates:
## Sen's slope 
##   -0.018174

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_874 <- standard_dev_874 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_874 <- fall_standard_dev_all_874 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_874 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.368829
1988 2.759711
1989 2.478007
1991 2.806539
1992 3.563246
1993 3.048611
1995 3.227383
1996 3.590269
1997 3.862000
1998 3.165820
1999 2.855746
2000 3.369828
2001 2.546798
2002 2.714691
2004 3.750472
2005 2.549391
2011 2.733772
2012 2.968158
2014 3.135127
2015 2.524485
2018 2.526677
2019 2.635960
2020 4.185425
2021 3.056579
2022 3.059427
ggplot(fall_standard_dev_all_874, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 874 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 874 (non-corrected)

fall_sd_mk_874 <- mk.test(fall_standard_dev_all_874$sd_2)
print(fall_sd_mk_874)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_874$sd_2
## z = 0.35032, n = 25, p-value = 0.7261
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 1.600000e+01 1.833333e+03 5.333333e-02
fall_sd_sens_874 <- sens.slope(fall_standard_dev_all_874$sd_2)
print(fall_sd_sens_874)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_874$sd_2
## z = 0.35032, n = 25, p-value = 0.7261
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02470768  0.03267679
## sample estimates:
## Sen's slope 
## 0.005925687

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_874_ad <- standard_dev_874_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_874_ad <- spring_standard_dev_all_874_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_874_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.004895
1988 3.840469
1989 3.330518
1991 3.286544
1992 2.929044
1993 2.587373
1995 2.940448
1996 3.462793
1997 3.258551
1998 3.151524
1999 3.484830
2000 3.500048
2001 3.327397
2002 2.784783
2004 2.957418
2005 3.378146
2011 3.717139
2012 3.228020
2014 3.965821
2015 3.148583
2018 2.821848
2019 3.618206
2020 2.646906
2021 3.080384
2022 3.098252
ggplot(spring_standard_dev_all_874_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 874 average spring temperatures for water years 1986-2021

spring MK & SS 874 (corrected)

spring_sd_mk_874_ad <- mk.test(spring_standard_dev_all_874_ad$sd_2)
print(spring_sd_mk_874_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_874_ad$sd_2
## z = -0.21019, n = 25, p-value = 0.8335
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -10.00000000 1833.33333333   -0.03333333
spring_sd_sens_874_ad <- sens.slope(spring_standard_dev_all_874_ad$sd_2)
print(spring_sd_sens_874_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_874_ad$sd_2
## z = -0.21019, n = 25, p-value = 0.8335
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02460609  0.01928894
## sample estimates:
##  Sen's slope 
## -0.003865878

Fall

fall_standard_dev_all_874_ad <- standard_dev_874_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_874_ad <- fall_standard_dev_all_874_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_874_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.205078
1988 2.560142
1989 2.327095
1991 2.621154
1992 3.313248
1993 2.853521
1995 2.952957
1996 3.346758
1997 3.558786
1998 2.894692
1999 2.659188
2000 3.112692
2001 2.288412
2002 2.516345
2004 3.821202
2005 2.582016
2011 2.733229
2012 2.995777
2014 3.196183
2015 2.472211
2018 2.498145
2019 2.688987
2020 4.235999
2021 3.058299
2022 3.101005
ggplot(fall_standard_dev_all_874_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 874 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 874 (corrected)

fall_sd_mk_874_ad <- mk.test(fall_standard_dev_all_874_ad$sd_2)
print(fall_sd_mk_874_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_874_ad$sd_2
## z = 1.3312, n = 25, p-value = 0.1831
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   58.0000000 1833.3333333    0.1933333
fall_sd_sens_874_ad <- sens.slope(fall_standard_dev_all_874_ad$sd_2)
print(fall_sd_sens_874_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_874_ad$sd_2
## z = 1.3312, n = 25, p-value = 0.1831
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01028338  0.04643860
## sample estimates:
## Sen's slope 
##  0.01751656

(getting git workflow errors…)